Two minor tweaks that I would suggest are:
1. When the program begins for the first time there is nothing on the pasteboard. The paste menu option should not be available in this situation. So in the -touchesBegan… method
Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *copyTouches = [event touchesForView:imageView];
NSSet *pasteTouches = [event touchesForView:pasteView];
UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:@"CopyPasteImage" create:YES];
NSData *data = [appPasteBoard dataForPasteboardType:
@"yourReverseDNS.CopyPasteImage.imageView"];
/*Sorry for the weird formatting but the site is inserting spaces where they don't belong and this is the only way I can get it to display correctly
*/
[self becomeFirstResponder];
if ([copyTouches count] > 0) {
[self performSelector:@selector(showMenu:) withObject:imageView afterDelay:0.9f];
}else if ([pasteTouches count] > 0 && data != nil)
{
[self performSelector:@selector(showMenu:) withObject:pasteView afterDelay:0.9f];
}
[super touchesBegan:touches
withEvent:event];
}
2. The Restore option should only be available if the imageView is hidden, since when it is visible there is nothing to restore. So in the -showMenu… method
Code:
-(void)showMenu:(id)view
{
self.selectedView = view;
UIMenuController *menu = [UIMenuController sharedMenuController];
if (view == pasteView && imageView.hidden == YES) {
UIMenuItem *menuItem = [[UIMenuItem alloc]
initWithTitle:@"Restore View"
action:@selector(restoreView:)];
menu.arrowDirection = UIMenuControllerArrowLeft;
menu.menuItems = [NSArray arrayWithObject:menuItem];
}
[menu setTargetRect:CGRectMake(5, 10, 1, 1) inView:view];
[menu setMenuVisible:YES animated:YES];
}
One question. Why have you made the pasteBoard persistent?
One comment. Cleanup is missing on p. 426 and 427 -viewDidUnload and -dealloc.
Bob