tabBarController = [[UITabBarController alloc] init]; //Create a tab bar
view1 = [[View1 alloc] init]; //Create the first view
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:view1];
navigationController1.navigationBar.tintColor =[UIColor blackColor];
view2 = [[View2 alloc] init]; //create the second view
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:view2];
navigationController2.navigationBar.tintColor =[UIColor blackColor];
tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController1, navigationController2,nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
上面的代碼來自我的appDelegate類(applicationDidFinishLaunching)。 View1和View2是UIViewController。這是我最初設計我的應用程序的方式,這些應用程序有兩個選項卡(view1和view2)。下面的代碼實現View1中發生的事情,當用戶向左或向右滑動時。與pushViewController有問題!幫助
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"I am in touches began methods");
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self.view];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.view];
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
//Set Animation Properties
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1];
if(gestureStartPoint.x > currentPosition.x){ //I am trying to move right
ViewControllerTemplate *newView = [[ViewControllerTemplate alloc] initWithNibName:@"ViewControllerTemplate" bundle:nil];
//Transition spin right
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
//Push OnTo NavigationController
[self.navigationController pushViewController:newView animated:YES];
}
else { //I am trying to move left
if([viewDelegate getCurrentViewID] > 0){ //At view 0, should not pop anymore view
//Transition Spin left
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[self.navigationController popViewControllerAnimated:YES];
}
}
[UIView commitAnimations];
}
}
差不多,它只是說,當用戶刷卡的權利,它創建一個新的視圖(ViewControllerTemplate)和pushViewController,當離開用戶刷卡,popViewController。但是,因爲我改變了主意,不想實現標籤欄。因此,我將appDlegate中的applicationDidFinishLaunching中的代碼更改爲下面的代碼,並在View1.m中的touchesMoved中的pushViewController停止工作。我確信它到達那裏,但是當它pushViewController的newView時,什麼都不會發生。我感覺當我拿出UINavigationController時,我的視圖不再適當地推入堆棧。任何想法,爲什麼,以及如何解決它
view1 = [[View1 alloc] init];
[window addSubview:View1.view];
你任何機會都知道如何將數據推送到UITouch上的另一個視圖,就像以前一樣。就像我們在didlectlectrowrowdexpath上做的那樣。 – lifemoveson