我大家,
我有一个带有图像的 NSArray,并且不能通过向左或向右平移(就像在 iPhone 照片库中一样)从一个图像传递到另一个图像。我的图片数组来自收藏视图。所以第一个显示的图像是我在集合视图中选择的那个。
现在,我可以显示正确的图像并将此图像向左或向右移动,但我不知道如何显示其他图像,当图像在我的视图中超过 50% 时,它会移动到中心。
非常感谢。
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
//NSLog(@"%i", _indexPhoto);
self.photoImageView.image = [UIImage imageNamed:[_photosCollectionArray objectAtIndex:_indexPhoto]];
UIPanGestureRecognizer *recognizer;
recognizer = [[UIPanGestureRecognizer alloc]initWithTarget: self action: @selector(panGestureHandle:)];
[recognizer setMinimumNumberOfTouches:1];
[recognizer setMaximumNumberOfTouches:1];
[[self view] addGestureRecognizer:recognizer];
}
-(void) panGestureHandle:(UIPanGestureRecognizer *) sender {
NSLog(@"Pan Gesture Handling");
UIPanGestureRecognizer *pangesture = (UIPanGestureRecognizer *)sender;
CGPoint translation = [pangesture translationInView:self.view];
CGPoint imageViewPosition = _photoImageView.center;
imageViewPosition.x += translation.x;
_photoImageView.center = imageViewPosition;
[pangesture setTranslation:CGPointMake(0, 0) inView:self.view];
}