私はiOSを初めて使用します。次の論理をもたらす可能性があるかどうかわからない。
1. UITabBarController has three UIViewController.
2. While Swipping horizontally in the second UIViewController, i want to move
to the third UIViewController.
出来ますか?。もしそうなら、親切に同じことを達成する方法をアドバイスしてください。
私はiOSを初めて使用します。次の論理をもたらす可能性があるかどうかわからない。
1. UITabBarController has three UIViewController.
2. While Swipping horizontally in the second UIViewController, i want to move
to the third UIViewController.
出来ますか?。もしそうなら、親切に同じことを達成する方法をアドバイスしてください。
2番目のViewControllerで、ViewDidLoadに次の行を追加します
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(gotoNextPage:)];
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
そしてメソッドを追加します
-(void)gotoNextPage:(id)sender {
[self.tabBarController setSelectedViewController:thirdViewController];
}
前のビューにポップするために私が行っているタッチデリゲートメソッドを使用できます
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint startPosoition = [touch previousLocationInView:self.view];
CGPoint endPosition = [touch locationInView:self.view];
if (endPosition.x - startPosoition.x > 20)
{
[self.navigationController popViewControllerAnimated:YES];
} else
{
}
}
はい、できます。1.の場合、ビューコントローラを使用してタブバーベースのアプリをセットアップする方法を知っていると思います。2.の場合2番目のビューコントローラのビューにスワイプジェスチャレコグナイザを実装し、ジェスチャハンドラで次の手順を実行します。[self.yourTabBarController setSelectedIndex:2];
このコードを使用してください。
UISwipeGestureRecognizer *swipeGestureNextPage = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(loadPreviousPageClicked)];
swipeGestureNextPage.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeGestureNextPage];
-(void)loadPreviousPageClicked
{
//use navigation controller here accordingly
}
それでおしまい。