2010-09-23 44 views
0

权的问题交换意见,我知道怎么做pictue书效应,但我在努力去除视图iPhone:就像一本图画书,与removeFromSuperView

所以第1页,我添加了通过addSubview第二页视图(通过一个滑动)。我还增加了一个柜台,所以我知道我在哪个页面上。

那么如何返回到第1页?见我认为这将是self.view removeFromSuperview但是当你试图返回到第2页

代码如下

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer { 

    if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) { 
    //NSLog(@"swipe right to left"); 

    UniversalAppAppDelegate *appDelegate = (UniversalAppAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    PictureBookViewController *viewController2 =(PictureBookViewController *) [appDelegate getViewControllerForViewID:@"81"]; 

    [UIView beginAnimations:Nil context:nil]; 
     [UIView setAnimationDuration:0.6]; 
     [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view.superview cache:YES]; 
    self.viewController = viewController2; 
    self.viewController.pageNo = self.pageNo + 1; 

     [self.view addSubview:self.viewController.view]; 
     [UIView commitAnimations]; 
    [viewController2 release]; 

} else { 

    //NSLog(@"swipe left to right"); 
    NSLog([NSString stringWithFormat:@"%d", self.pageNo]); 
    if (self.pageNo > 0) { 

    [UIView beginAnimations:Nil context:nil]; 
    [UIView setAnimationDuration:0.6]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view.superview cache:YES]; 

    //self.viewController = viewController2; 
    //self.viewController.pageNo = self.pageNo - 1; 
    //[self.view addSubview:self.viewController.view]; 

    [self.view removeFromSuperview]; 
    //[self.view addSubview:self.viewController.view]; 
    [UIView commitAnimations]; 

    } 
    } 
} 

更新的崩溃:

每个视图都有自己的看法控制器。

+0

你能否正确地格式化你的代码? – 2010-09-23 11:25:30

+0

对不起,对不起 – Burf2000 2010-09-23 11:28:38

回答

1

你想删除你的viewController的视图,而不是容器的视图。

[self.viewController.view removeFromSuperview]; 
+0

正确的我做了你的改变,现在它保留第2页,并删除第1页。所以,如果页1有粉红色背景,页2有红色背景,粉红色背景不会回来,当你向后滑动,红色的只是重新出现 – Burf2000 2010-09-23 11:42:08

0

这似乎工作,而不是崩溃?我现在确信它是正确的。我似乎需要一种删除最后添加的子视图的方法。我的第一个观点不是超级景观

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer { 

    if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) { 
     //NSLog(@"swipe right to left"); 

     UniversalAppAppDelegate *appDelegate = (UniversalAppAppDelegate *)[[UIApplication sharedApplication] delegate]; 
     PictureBookViewController *viewController2 =(PictureBookViewController *) [appDelegate getViewControllerForViewID:@"82"]; 

     [UIView beginAnimations:Nil context:nil]; 
     [UIView setAnimationDuration:0.6]; 
     [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view.superview cache:YES]; 
     self.viewController = viewController2; 
     self.viewController.pageNo = self.pageNo + 1; 
     self.viewController.lastViewController = self; 
     [self.view addSubview:self.viewController.view]; 
     [UIView commitAnimations]; 
     [viewController2 release]; 

    } else { 

     //NSLog(@"swipe left to right"); 
     NSLog([NSString stringWithFormat:@"%d", self.pageNo]); 
     if (self.pageNo > 0) { 

      [UIView beginAnimations:Nil context:nil]; 
      [UIView setAnimationDuration:0.6]; 
      [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view.superview cache:YES]; 
      self.pageNo --; 
      self.view = self.viewController.view; 
      [self.view removeFromSuperview ]; 
      self.view = self.lastViewController.view; 

      [UIView commitAnimations]; 

     } 
    } 
}