2010-09-23 47 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]; 

     } 
    } 
}