【问题标题】:How to show second button on pressing first one in Objective-C如何在Objective-C中按下第一个按钮时显示第二个按钮
【发布时间】:2018-04-04 19:19:10
【问题描述】:

我是 iPhone 编程的新手(目标 C)。我想制作一个在长按另一个按钮时可见的按钮。就像系统键盘样式一样。我应该通过将手指放在它们上来选择第一个或第二个按钮:-) 我该怎么做,我找不到教程。谢谢

【问题讨论】:

标签: ios objective-c xcode custom-keyboard


【解决方案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
     }
}

【讨论】:

    猜你喜欢
    • 2017-08-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    • 2021-05-22
    相关资源
    最近更新 更多