Frage

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];

Der obige Code stammt aus meiner AppDelegate -Klasse (applicationDidfinishlaunching). View1 und View2 sind UIViewController. So habe ich ursprünglich meine Apps gestaltet, dass die Apps zwei Registerkarten haben (Ansicht 1 und Ansicht2). Im Folgenden im folgenden Code implementieren Sie das, was in View1 passiert, wenn der Benutzer nach links oder rechts streift.

- (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];
}
}

Ziemlich genau heißt es nur, dass der Benutzer, wenn er nach rechts streift, eine neue Ansicht (ViewControllertemplate) und PushViewController erstellt und wenn der Benutzer nach links streift, popviewController. Da ich jedoch meine Meinung ändere und nicht die Registerkartenleiste implementieren möchte. Daher ändere ich meinen Code in ApplicationDidfinishlaunching in AppDelegate auf diese unten und den PushviewController in toppesmoved in View1.M Stop Work. Ich bin mir sicher, dass es dort ankommt, aber wenn es PusviewController des Newviews ist, passiert nichts. Ich habe das Gefühl, als ich den UinavigationController herausgenommen habe, ist meine Sicht nicht mehr richtig auf den Stapel. Jede Idee warum und wie man es behebt

view1 = [[View1 alloc] init];
[window addSubview:View1.view];
War es hilfreich?

Lösung

Wenn jemand jemals auf das gleiche Problem stoßen, ersetzen Sie hier die Lösung, was ich für die AnwendungDidfinishlaunching () dort oben dazu habe

view1 = [[View1 alloc] initWithNibName:@"View1" bundle:nil];    //Create the first view
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:view1];
navigationController1.navigationBar.tintColor =[UIColor blackColor];
view1 = navigationController1;  
[window addSubview:view1.view];
[window makeKeyAndVisible];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top