开发者

How to let the pageController control the UIImageView?

开发者 https://www.devze.com 2022-12-28 18:51 出处:网络
I want a UIImageView swipe left, the UIImageView will change the image, at this time, the pageController +1, if swipe right, the pageContoller -1, and display the previ开发者_开发技巧ous image... ...H

I want a UIImageView swipe left, the UIImageView will change the image, at this time, the pageController +1, if swipe right, the pageContoller -1, and display the previ开发者_开发技巧ous image... ...How can I implement it? Any simple code? thz u.


Just attach a UISwipeGestureRecognizer to the UIImageView. When the gesture recognizer triggers, you would check it's direction and then change images and update the pageController accordingly.


UIGestureRecognizer *recognizer;

recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(next:)];
UISwipeGestureRecognizer *swipeLeftRecognizer = (UISwipeGestureRecognizer *)recognizer;
swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeftRecognizer];
swipeLeftRecognizer=nil;
[recognizer release];

recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(prev:)];
UISwipeGestureRecognizer *swipeRightRecognizer = (UISwipeGestureRecognizer *)recognizer;
swipeRightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRightRecognizer];
swipeLeftRecognizer=nil;
[recognizer release];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号