我在本教程后面创建了图像Swipe Gesture:the tutorial
图像swiper工作正常但我需要你的帮助 - 如何复制此代码以制作更多“swipers”,具有不同的图像。 有没有编码的简单方法可以做到这一点?
代码是:(viewcontroller.m)
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
NSInteger imageindex = 2;
- (IBAction)handleswipe:(UIGestureRecognizer *)sender {
NSLog( @"swiped");
NSArray *images=[[NSArray alloc] initWithObjects:
@"vodkacomp1.jpg",
@"vodkacomp2.jpg", nil];
UISwipeGestureRecognizerDirection direction =
[(UISwipeGestureRecognizer *) sender direction];
switch (direction) {
case UISwipeGestureRecognizerDirectionLeft:
imageindex++;
break;
case UISwipeGestureRecognizerDirectionRight:
imageindex--;
break;
default:
break;
}
imageindex = (imageindex < 0) ? ([images count] -1):
imageindex % [images count];
_vodkacom.image = [UIImage imageNamed:[images objectAtIndex:imageindex]];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
viewcontroller.h:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *vodkacom;
- (IBAction)handleswipe:(UIGestureRecognizer *) sender;
@end