如何让pageController控制UIImageView?

发布于 2024-08-30 19:01:23 字数 125 浏览 10 评论 0原文

我想要一个UIImageView向左滑动,UIImageView会改变图像,此时pageController +1,如果向右滑动,pageContoller -1,并显示上一个图像......我该如何实现?有简单的代码吗? thz u。

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 previous image... ...How can I implement it? Any simple code? thz u.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风和你 2024-09-06 19:01:23

只需将 UISwipeGestureRecognizer 附加到 UIImageView 即可。当手势识别器触发时,您将检查其方向,然后更改图像并相应地更新 pageController。

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.

无声无音无过去 2024-09-06 19:01:23
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];
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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文