如何在Objective-C中按第一个按钮时显示第二个按钮

时间:2017-10-24 05:43:15

标签: ios objective-c xcode custom-keyboard

我是iPhone编程新手(Objective C)。我想制作长按另一个按钮时可见的按钮。就像系统键盘风格一样。我应该用手指按住它们来选择第一个或第二个按钮:-)我怎么能这样做,我找不到教程。感谢

1 个答案:

答案 0 :(得分:1)

创建UILongPressGestureRecognizer实例并将其附加到UIButton

-(IBAction)SelectImage:(id)sender
{
      UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressMethod:)];
      [self.button addGestureRecognizer:longPress];
}      

然后创建处理手势的方法

- (void)longPressMethod:(UILongPressGestureRecognizer*)gesture 
{
     if ( gesture.state == UIGestureRecognizerStateEnded ) 
     {
          NSLog(@"Long Press");
          //Do your code here what you want to perform
     }
}