1
我想要一個UIImageView向左滑動,UIImageView將更改圖像,此時,pageController +1,如果向右滑動,pageContoller -1,並顯示上一張圖像......我該如何實現它?任何簡單的代碼?你好。如何讓pageController控制UIImageView?
我想要一個UIImageView向左滑動,UIImageView將更改圖像,此時,pageController +1,如果向右滑動,pageContoller -1,並顯示上一張圖像......我該如何實現它?任何簡單的代碼?你好。如何讓pageController控制UIImageView?
只需將UISwipeGestureRecognizer附加到UIImageView。當手勢識別器觸發時,您會檢查它的方向,然後更改圖像並相應地更新pageController。
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];