在這裏我有三個視圖,一個是左,中,右,所以我想添加滑動功能,我嘗試了以下方法,但仍然無法使它。如何做到這一點。添加滑動手勢,無法滑動
CODE:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
UISwipeGestureRecognizer *gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerRight:)];
[gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.view addGestureRecognizer:gestureRecognizer];
//Left Swipe
UISwipeGestureRecognizer *gestureRecognizer2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerLeft:)];
[gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.view addGestureRecognizer:gestureRecognizer2];
}
轉型爲右
-(void)swipeHandlerRight:(id)sender
{
RightViewController *videoScreen=[self.storyboard instantiateViewControllerWithIdentifier:@"RightViewController"];
CATransition* transition = [CATransition animation];
transition.duration = 0;
transition.type = kCATransitionFromRight;
// transition.subtype = kCATransitionFromRight;
[self.view.window.layer addAnimation:transition forKey:kCATransition];
[self presentViewController:videoScreen animated:NO completion:nil];
}
轉變爲左
-(void)swipeHandlerLeft:(id)sender
{
LeftViewController *videoScreen=[self.storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"];
CATransition* transition = [CATransition animation];
transition.duration = 0;
transition.type = kCATransitionFromLeft;
// transition.subtype = kCATransitionFromRight;
[self.view.window.layer addAnimation:transition forKey:kCATransition];
}
你想達到什麼,我認爲你應該使用頁面視圖控制器或在滾動視圖中放置3個視圖並啓用分頁。根據您的要求,讓scrollview的寬度儘可能大。 –
那些方法是不是一次性調用? – Nilesh
@NileshJha當我加入一個斷點,並運行該程序的視圖會出現被調用,當我向左滑動該斷點轉到leftViewController和同爲右,但仍中間標籤是出現在那裏,當我應該表現出左側標籤向左滑動,因爲我在各自的屏幕上添加了標籤 – virat