【发布时间】:2016-03-04 05:05:58
【问题描述】:
我正在开发一个食品应用程序,其中每个 tableViewCell 显示不同的食谱名称。当用户点击食谱(在单元格中)时,将打开详细视图。
我现在正在尝试为UIImageView 实现滑动手势,它会在滑动时显示不同的图像。我该如何实现?
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeImage:)];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeImage:)];
// Setting the swipe direction.
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
// Adding the swipe gesture on image view
[Allimages addGestureRecognizer:swipeLeft];
[Allimages addGestureRecognizer:swipeRight];
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe{
NSInteger indexPath;
if (indexPath==0) {
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
arrayimage=[[NSMutableArray alloc]initWithObjects:@ "BBQ Chicken Pizza.jpg",@ "roastchickensteaks.jpg", nil];
swipee = (swipee > 0)? ([arrayimage count]-1):
swipee%[arrayimage count];
Allimages.image=[UIImage imageNamed: [arrayimageobjectAtIndex:indexPath]];
}}
http://i.stack.imgur.com/apDEw.png
【问题讨论】:
标签: ios objective-c uitableview uiimage uiswipegesturerecognizer