0

絵本効果のやり方はわかるけど、ビューを消すのに苦労している

ページ 1 では、addSubview (スワイプ) を介して 2 番目のページ ビューを追加します。また、カウンターをインクリメントして、自分がどのページにいるかを把握します。

では、どうすれば 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 に答える