你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS-自定義手勢操作

iOS-自定義手勢操作

編輯:IOS開發綜合

1.自定義全局手勢操作

@property (nonatomic, strong) UIPanGestureRecognizer *panGestureRecognizer;

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //原生方法無效
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    //設置手勢
    self.panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(openMenuClick)];
    [self.view addGestureRecognizer:self.panGestureRecognizer];

}

-(void)openMenuClick{
    //進行相應操作
    NSLog(@"進行相應操作");
}

2.局部手勢

/** 左滑手勢 */
@property (nonatomic, strong) UIScreenEdgePanGestureRecognizer *edgePanGestureRecognizer;

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //原生方法無效
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;

    self.edgePanGestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(openMenuClick)];
    self.edgePanGestureRecognizer.delegate = self;
    self.edgePanGestureRecognizer.edges = UIRectEdgeRight;
    [self.view addGestureRecognizer:self.edgePanGestureRecognizer];
}

-(void)openMenuClick{
    //進行相應操作
    NSLog(@"進行相應操作");
}
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved