我使用了以下代码,但是当我运行程序时,滑动不起作用。
首先,我在接口部分添加了手势识别器协议
#import <UIKit/UIKit.h>
@interface BNRViewController : UIViewController <UIGestureRecognizerDelegate>
@property (nonatomic,strong) IBOutlet UILabel *swipe;
@end
现在,我在工具部分实例化了滑动手势识别器
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(fingerSwipe:)];
swipeUp.numberOfTouchesRequired = 3;
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeUp];
}
谁能帮我吗
最佳答案
除非您在标签上将 userInteractionEnabled设置为YES ,否则手势识别器将无法工作。
因此,您必须添加此行[swipe setUserInteractionEnabled:YES];
,它已在工作,我已经检查过。
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(fingerSwipe:)];
[swipe setUserInteractionEnabled:YES];
swipeUp.numberOfTouchesRequired = 1;
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeUp];
关于ios - UISwipeGestureRecognizer在iOS模拟器中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23308232/