配列には 8UIImageView
つの画像があり、一度に配列から 1 つの画像が表示されます。また、ユーザーが画像UIPanGestureRecognizer
上UIImageView
で指を横に動かすと、画像が変化します(画像の上部にある目に見えないスクローラーのようなものです)。パン ジェスチャの変換値を使用して画像を変更しています。これはすべて機能しますが、私が望む方法ではありません。画像の変化が速すぎます。短い指のパンで画像をスクロールするだけです。画像を変更するために長いパンを必要とする方法はありますか? または、ユーザーにとってこれを「よりスムーズ」にする他の方法はありますか?
.h
@interface FirstViewController : UIViewController
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
- (IBAction)pan:(UIGestureRecognizer *)panGesture;
.m
@interface FirstViewController () {
NSArray * imageArray;
int _currentIndex;
}
@end
@implementation FirstViewController
- (IBAction)pan:(UIPanGestureRecognizer *)panGesture {
// NSLog(@"panned");
CGPoint translation = [panGesture translationInView:self.view];
[self.panLabel setText: NSStringFromCGPoint(translation)];
NSLog(@"%@ translation", NSStringFromCGPoint(translation));
if (translation.x<-1) {
_currentIndex=(_currentIndex<=0)?0:_currentIndex-1;
UIImage *img = [UIImage imageNamed:[imageArray objectAtIndex:_currentIndex]];
[self.imageView setImage:img];
}
else if(translation.x>1){
_currentIndex=(_currentIndex>=7)?7:_currentIndex+1;
UIImage *img = [UIImage imageNamed:[imageArray objectAtIndex:_currentIndex]];
[self.imageView setImage:img];
}
[panGesture setTranslation:CGPointZero inView:self.view];
}
- (void)viewDidLoad {
[super viewDidLoad];
imageArray = [[NSArray alloc]
initWithObjects:@"image1.jpg", @"image2.jpg", @"image3.jpg", @"image4.jpg", @"image5.jpg", @"image6.jpg", @"image7.jpg", @"image8.jpg", nil];
}