Getting screen coordinates from UILongPressGestureRecognizer - uigesturerecognizer

I am trying to implement a UILongPressGestureRecognizer in an iOS app. It fires as expected, but I don't see anyway of passing screen coordinates to my target method. Does anyone know how to do this?

This seems to work as an action:
- (void)receivedLongPress:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint coords = [gestureRecognizer locationInView:gestureRecognizer.view];
}
I still don't really understand (it seems like the last touch point is stored in the gestureRecognizer, in which case I would expect there to just be a property or something). But hey, it works.

Related

How can I make a label smoothly disappear after a certain time in my app?

I am using Xcode to create a Cocoa app for Mac OSX written in Objective-C. I was wondering if I could use an NSTimer to make a label Smoothly disappear after a certain time after I have clicked a button.
Or I thought I could use this code:
- (IBAction)clickToLoadAppButtonClicked:(id)sender; {
[self performSelector:#selector(delayedLoad) withObject:nil afterDelay:3.0]
}
All I would need to do would be to add a void function called delayedLoad. I just need to know the code to make the label smoothly disappear so I can put it in the void...
Please help and thanks guys :D
You can do it using core animation:
[[myLabel animator] setAlphaValue:0.0];
This animates to transparent over a default period of 0.25 seconds.
See here for some further explanation or here for the full docs.

How to move an image

I am creating an app where bombs come into the screen and blow up this thing that you have to move. How do I make these bombs fly into the screen and move in random directions automatically ? Kind of like fruit ninja where the fruits fly out at you. How do I code that ? What do I need to do ? Please also provide some code. Thank you !
Create a class, called Bomb or something and it needs to have an instance variable and property of CGRect on iOS or NSRect on Mac OS.
Then create a method that can draw the bomb on the screen, like - drawOnScreen or just - draw which knows how to draw the object. Which would contain code like [[UIImage imageNamed:#"bomb1"] drawInRect:self.frame]
Then in your game loop you simple change the coordinates of the frame of such a bomb object to make it move, of course you will need to do that before calling the draw method as it would draw the previous frame then..
There also is another way of adding a subview to the gameview every time you need a new bomb. However a view has more overhead than using the object I described above and would most likely cause your game to run slow if you have like 50/60+ ( wild guess ) bombs.
For controls on the screen like a pause button I would definitely use a view and add it as a subview.

My DetailViewController isn't recognizing the '-configureView'

I had a problem with the splitView so I decided to make my own version of it using a ViewBasedApplication. The view is set up to be like a splitView, but instead of having the static table when you flip it to landscape it will have the popover control like it normally does in the portrait mode.
I have everything set up, but I'm encountering an error when I select an item from the popover table. It isn't updating the view to go to the appropriate page that was selected in the table...the code for the setDetailItem in the ViewController.m file looks like this:
-(void)setDetailTime:(id)newDetailItem{
if(detailitem != newDetailItem) {
[detailitem release];
detailItem = [newDetailItem retain[;
[self configureView];
...
}
The problem is in the [sef configureView] line. it says that "PDFViewController" may not respond to '-configureView'. Im assuming this is because '-configureView' is specific to only the SplitView. Any ideas of a way to workaround this issue?
Thanks!
Your class PDFViewController does not have a configureView method, which is why you're getting the warning (and why you're not seeing anything happen).
You probably need to instead call [self.view setNeedsDisplay] which basically tells the view to redraw itself. I don't know if this will work for you, because I don't know how the rest of your class is written.

Changing selection state of IKImageBrowserView

Hey guys, I've just migrated my image selector from NSCollectionView to IKImageBrowserView. I've got almost everything set up the way I want it, except for the selection ring. I don't like the greyed out background that IKImageBrowserView defaults to, and I wanted to do a yellow stroke around the edge of my selected image to indicate it's selection (like in iPhoto). Is is possible to override the draw state of IKImageBrowserCell? I haven't been able to find any way to do it yet. It doesn't have the simple drawRect methods that I'm used to. Any help would be appreciated. I'm assuming I have to use CALayers?
I overrode - (CALayer *)layerForType:(NSString *)type and tried just as a test, setting the layer corner radius to 0, but it didn't seem to change anything. The method is being called because if I throw a breakpoint in it, it stops there. However, even if I return nil from that method, it still draws the images like usual.
Thanks!
That is the right method for customizing the IKImageBrowserCell.
Using CALayers and configuring different attributes, you can control many facets of how the images are presented.,
A layer of type = IKImageBrowserCellSelectionLayer is what you will want to change to have the display behave and present as you wish.
Here's a link to Apple's sample code project that will get you started

resetting the image in an NSView

I think this is a very simple question, but I’m new to programming so I may be going about it in a wrong-headed way.
I have a basic understanding of Objective-C writing terminal applications and am teaching myself how to use the Cocoa GUI.
I understand how to use IBOutlet and IBAction to connect a simple button to a method that will repeatedly send random numbers to a textfield.
I understand how to add a NSView file, connect it to a custom view in interface builder and draw a path through random points in the view when the application launches.
(I’ve been putting this code inside the - (void)drawRect:(NSRect)dirtyRect method that is declared when the file is created).
What I can’t seem to figure out is how to connect a button to an action that will then ‘refresh’ the view – in this case repopulate it with another set of random points connected with a path. Looking at the documentation, I think I should somehow be using
– (void) setNeedsDisplay(BOOL)flag
but nothing I have tried so far had worked. Please tell me, what am I missing here?
Something like this:
- (IBAction)refreshButtonAction:(id)sender
{
[theView setNeedsDisplay:YES];
}
Connect your button to that action. "theView" is a reference to your custom NSView.

Resources