ios UISwipeGestureRecognizer 左右滑动隐藏按钮

来源:互联网 发布:pdf拆分软件绿色版 编辑:程序博客网 时间:2024/06/16 09:01


#import "loginSuccessViewController.h"@interface loginSuccessViewController (){    UIButton *_ljBackButton;}@end@implementation loginSuccessViewController- (void)viewDidLoad{    [super viewDidLoad];    _ljBackButton = [UIButton buttonWithType:UIButtonTypeCustom];    [_ljBackButton setFrame:CGRectMake(100, 200, 100, 44)];    [_ljBackButton setBackgroundColor:[UIColor grayColor]];    //[_ljBackButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];    [_ljBackButton setTitle:@"测试" forState:UIControlStateNormal];    [_ljBackButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];    [self.view addSubview:_ljBackButton];        // 添加右滑移除手势    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToDirection:)];    swipeRight.direction = UISwipeGestureRecognizerDirectionRight;    [_ljBackButton addGestureRecognizer:swipeRight];        // 添加右滑移除手势    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToDirection:)];    swipeRight.direction = UISwipeGestureRecognizerDirectionLeft;    [_ljBackButton addGestureRecognizer:swipeLeft];}- (void)swipeToDirection:(UISwipeGestureRecognizer *)swipeGesture{    if (swipeGesture.direction == UISwipeGestureRecognizerDirectionRight)    {        // 向右滑动        NSLog(@"-----DirectionRight");        [_ljBackButton setHidden:YES];    }    else if (swipeGesture.direction == UISwipeGestureRecognizerDirectionLeft)    {        // 向左滑动        NSLog(@"-----DirectionLeft");        [_ljBackButton setHidden:YES];    }}@end


原创粉丝点击