ios左右滑動手勢

來源:互聯網
上載者:User

標籤:

 8  9 #import "ViewController.h"10 11 @interface ViewController ()12 13 @property (nonatomic, strong) UISwipeGestureRecognizer *leftSwipGestureRecognizer;14 @property (nonatomic, strong) UISwipeGestureRecognizer *rightSwipGestureRecognizer;15 16 @end17 18 @implementation ViewController19 20 - (void)viewDidLoad {21     [super viewDidLoad];22     // Do any additional setup after loading the view, typically from a nib.23     24     _leftSwipGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];25     _rightSwipGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];26     _leftSwipGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;27     _rightSwipGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;28     29     [self.view addGestureRecognizer:self.leftSwipGestureRecognizer];30     [self.view addGestureRecognizer:self.rightSwipGestureRecognizer];31 }32 33 -(void)handleSwipes:(UISwipeGestureRecognizer *)sender34 {35     if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {36         [UIView animateWithDuration:0.5 animations:^{37             CGRect frame = self.swipLabel.frame;38             self.swipLabel.frame = CGRectMake(frame.origin.x - 100, frame.origin.y, frame.size.width, frame.size.height);39         }];40     }else if(sender.direction == UISwipeGestureRecognizerDirectionRight){41         [UIView animateWithDuration:0.5 animations:^{42             CGRect frame = self.swipLabel.frame;43             self.swipLabel.frame = CGRectMake(frame.origin.x + 100, frame.origin.y, frame.size.width, frame.size.height);44         }];45     }46 }47 48 - (void)didReceiveMemoryWarning {49     [super didReceiveMemoryWarning];50     // Dispose of any resources that can be recreated.51 }52 53 @end

 

ios左右滑動手勢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.