单击按钮(始终启用)取消最近的 *** 作.
(如果没有最近的撤消 *** 作,它将显示撤消/重做菜单).
长按“撤消”按钮可打开“撤消/重做”菜单.
我搜索了实现这个的方法,到目前为止我找到的最佳答案是在following link.
我想知道是否有人知道更简单的方法?
谢谢!
@H_502_4@解决方法 在回顾了所有方法并与朋友讨论之后,下面是我使用的解决方案,对于UIbarbuttonItem,它响应两个点击并长按(TapOrLongPressbarbuttonItem).它基于以下原则:
>子类UIbarbuttonItem
>使用自定义视图(因此处理长按非常简单 – 因为我们的自定义视图对长按手势处理程序没有问题…)
…到目前为止 – 这种方法是在other SO thread – 我不喜欢这种方法,因为我找不到足够简单的方法使自定义视图看起来像iPad导航栏按钮… Soooo …
使用水娄UIGlossyButton(感谢水!).这个用法封装在子类中……
结果代码如下:
@protocol TapOrPressbuttonDelegate;@interface TapOrPressbarbuttonItem : UIbarbuttonItem { UIGlossybutton* _tapOrPressbutton; __weak ID<TapOrPressbuttonDelegate> _delegate;}- (ID)initWithTitle:(Nsstring*)Title andDelegate:(ID<TapOrPressbuttonDelegate>)delegate;@end@protocol TapOrPressbuttonDelegate<NSObject>- (voID)buttonTapped:(UIbutton*)button withbarbuttonItem:(UIbarbuttonItem*)barbuttonItem;- (voID)buttonLongpressed:(UIbutton*)button withbarbuttonItem:(UIbarbuttonItem*)barbuttonItem;@end@implementation TapOrPressbarbuttonItem- (voID)buttonLongpressed:(UILongPressGestureRecognizer*)gesture { if (gesture.state != UIGestureRecognizerStateBegan) return; if([_delegate respondsToSelector:@selector(buttonLongpressed:withbarbuttonItem:)]) { [_delegate buttonLongpressed:_tapOrPressbutton withbarbuttonItem:self]; }}- (voID)buttonTapped:(ID)sender { if (sender != _tapOrPressbutton) { return; } if([_delegate respondsToSelector:@selector(buttonTapped:withbarbuttonItem:)]) { [_delegate buttonTapped:_tapOrPressbutton withbarbuttonItem:self]; } }- (ID)initWithTitle:(Nsstring*)Title andDelegate:(ID<TapOrPressbuttonDelegate>)delegate { if (self = [super init]) { // Store delegate reference _delegate = delegate; // Create the customm button that will have the iPad-nav-bar-default appearance _tapOrPressbutton = [UIGlossybutton buttonWithType:UIbuttonTypeCustom]; [_tapOrPressbutton setTitle:Title forState:UIControlStatenormal]; [_tapOrPressbutton setNavigationbuttonWithcolor:[UIcolor colorWithRed:123.0/255 green:130.0/255 blue:139.0/255 Alpha:1.0]]; // Calculate wIDth... CGSize labelSize = CGSizeMake(1000,30); labelSize = [Title sizeWithFont:_tapOrPressbutton.TitleLabel.Font constrainedToSize:labelSize lineBreakMode:UIlineBreakModeMIDdleTruncation]; _tapOrPressbutton.frame = CGRectMake(0,labelSize.wIDth+20,30); // Add a handler for a tap [_tapOrPressbutton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventtouchUpInsIDe]; // Add a handler for a long-press UILongPressGestureRecognizer* buttonLongPress_ = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(buttonLongpressed:)]; [_tapOrPressbutton addGestureRecognizer:buttonLongPress_]; // Set this button as the custom vIEw of the bar item... self.customVIEw = _tapOrPressbutton; } return self;}// Safe guards...- (ID)initWithImage:(UIImage *)image style:(UIbarbuttonItemStyle)style target:(ID)target action:(SEL)action { NSLog(@"%s not supported!",__FUNCTION__); return nil;}- (ID)initWithImage:(UIImage *)image landscapeImagePhone:(UIImage *)landscapeImagePhone style:(UIbarbuttonItemStyle)style target:(ID)target action:(SEL)action { NSLog(@"%s not supported!",__FUNCTION__); return nil;}- (ID)initWithTitle:(Nsstring *)Title style:(UIbarbuttonItemStyle)style target:(ID)target action:(SEL)action { NSLog(@"%s not supported!",__FUNCTION__); return nil;}- (ID)initWithbarbuttonSystemItem:(UIbarbuttonSystemItem)systemItem target:(ID)target action:(SEL)action { NSLog(@"%s not supported!",__FUNCTION__); return nil;}- (ID)initWithCustomVIEw:(UIVIEw *)customVIEw { NSLog(@"%s not supported!",__FUNCTION__); return nil;}@end
你需要做的就是:
1.实例化如下:
TapOrPressbarbuttonItem* undoMenubutton = [[TapOrPressbarbuttonItem alloc] initWithTitle:NSLocalizedString(@"Undo",@"Undo Menu Title") andDelegate:self];
2.将按钮连接到导航栏:
[self.navigationItem setleftbarbuttonItem:undoMenubutton animated:NO];
3.实现TapOrPressbuttonDelegate协议,你就完成了……
-(voID)buttonTapped:(UIbutton*)button withbarbuttonItem:(UIbarbuttonItem*)barbuttonItem { [self menuItemUndo:barbuttonItem];}-(voID)buttonLongpressed:(UIbutton*)button withbarbuttonItem:(UIbarbuttonItem*)barbuttonItem { [self undoMenuClicked:barbuttonItem];}
希望这有助于其他人……
@H_502_4@ @H_502_4@ @H_502_4@ @H_502_4@ 总结以上是内存溢出为你收集整理的ios – iPad撤消按钮(a-la Keynote和其他应用程序)全部内容,希望文章能够帮你解决ios – iPad撤消按钮(a-la Keynote和其他应用程序)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)