Undo button for drawing app - objective-c

I made an iPad drawing app and I want it to have an "Undo" button that will remove the last object drawn on the screen.
How can do that? I already have the button connected to its outlet and action.

Essentially, you will need to keep a version of the the image before the new object is drawn on it, and if the user decides to abandon the drawing, revert back to the previous image.
If you want more then one level of undo it may be easier to keep a description of all of the actions performed by the user and repeat them up to the last undo.

Related

UIFocusGuide: only forward if system has no solution

I have a wide "dock" area at the bottom of the screen. I have placed a UIFocusGuide across the top of it. Depending on which element in the dock has focus, the system may or may not have a focus solution if the user swipes up.
How can I tell my focus guide to use the system-calculated new focus item if there is one, but if not, it should use the one configured in my setPreferredFocusEnvironments:
Alternatively, is there a way to determine where a "swipe up" will take the focus without actually doing it? As the focused element in the dock changes, I could check this and if it has no destination provided by the system, I can add one.
My dock is a view within a main view controller but preferredFocusEnvironments is never called when the user tries to move to a non-existent view from an element in the dock.

In Objective-C/Cocoa, are there global events for when mission control is activated or spaces are changed?

I'm currently working on an OSX menubar app that uses a custom status item view and a NSPopover to display content.
I'm trying to get it to dismiss at times that would make sense like when spaces are changed, since the popover doesn't move spaces like a window does, or when mission controller is activated.
Currently, when in mission control, the NSPopover stays on top as shown in this screenshot.
Currently I'm using NSEvent addGlobalMonitorForEventsMatchingMask: with some mouse event masks and that works alright but doesn't cover all needed events.
So, is there a way to detect when major OS events happen like opening mission control, changing spaces etc?
Any help would be greatly appreciated.
You can get notified of space changes by registering for NSWorkspace's NSWorkspaceActiveSpaceDidChangeNotification. There isn't a notification as such for Mission Control, but you might investigate whether NSWorkspaceDidActivateApplicationNotification or other notifications can be used to determine what you need.
HTH

How to cancel a drag in a Mac application

I have an application that has a canvas (NSView) where a user can drag an element around. When the mouse leaves the edge of that view it becomes a drag operation.
What I would like to do is when the mouse entered the originating view again it would cancel the operation and would automatically start the move within the canvas again.
I can figure out the second part I just need to figure out how to force a drag and drop to cancel. I need to do this somehow from draggingEntered: so before the mouse is even released.
Make your canvas view respond to drags as well. Initially all its <NSDraggingDestionation> protocol methods would just return “no, do nothing”, but if you start a drag from within the canvas you’d keep track of that, and once the drag leaves and comes back your NSDraggingDestionation methods would return, “Ok, we accept, drag is over, don’t bother animating.”
Then you could continue tracking locally. Like, assuming your canvas had called:
- (void)dragImage:(NSImage *)anImage at:(NSPoint)viewLocation offset:(NSSize)initialOffset event:(NSEvent *)event pasteboard:(NSPasteboard *)pboard source:(id)sourceObj slideBack:(BOOL)slideFlag;
That method would then return control to your canvas

Reverse animation before it is finished

I have a button and when the user touches down and holds a popup appears. However, when the user releases his thumb before the pop animation finishes I'd like the animation to stop where it is and autoreverse to the initial position. How can I accomplish this?
Currently I'm simply using UIViews -animateWithDuration:animations:completion:. Do I have to set the animations explicitly in this case?
I've already tried reading the current state from the presentationLayer properties, but that somehow didn't work.
You can start the second animation using the UIViewAnimationOptionBeginFromCurrentState option. This will stop the first animation if it's still running.

How can I differ between manual and automatic scrolling in NSScrollView/NSTextView

I subclassed NSTextView and added support for automatic scrolling in a userdefineable time.
Now I want to detect, if the user manually scrolls, while the view is scrolling automatically.
Then I want to immediately stop automatic scrolling, until the user stops his action and then I want to start scrolling again from the new position.
I want to do this in such a matter, that the user can move around without a stuttering view.
I use boundsDidChangeNotification to calculate the scrolling position (playtime) and show it in a label, but I can't use it to detect the user manual scrolling, because it is also pushed by the automatic scrolling...
Would be very nice, if anyone has an idea ;-)
Thanks in advance
Gerald