0

是的,我知道如何制作图画书效果,但我努力删除视图

所以第 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];

  }
    }
}

更新:

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

4

2 回答 2

1

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

[self.viewController.view removeFromSuperview];
于 2010-09-23T11:29:06.943 回答
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];

        }
    }
}
于 2010-09-23T13:15:58.560 回答