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