0

私はここでひどく簡単なものを見逃していると確信しています...

初めて画像をループすると、インデックスがリセットされて適切にインクリメントされますが、UIView は更新されず、配列の最後の画像が表示されたままになります。transitionFromView: サブビューを自動的に入れ替えますよね? 補完: オプションを実装する必要がありますか?

私は何が欠けていますか?関連するコードは次のとおりです。

    - (id)initWithFrame:(CGRect)frame
    {
        NSInteger maxSlides = 12;
        self = [super initWithFrame: frame];
        if (self) {
            //set up an array of images to be used for a flipbook    
            slides = [[NSMutableArray alloc] initWithCapacity: maxSlides]; 

            for(NSInteger i=0; i<maxSlides; ++i) {
               imageView = [[UIImageView alloc] initWithImage:                
               [UIImage imageNamed:[NSString stringWithFormat: @"muybridge%d.png", i]]];

               [slides addObject: imageView];
            } 

            index = 0; //default to first photo.

            [self addSubview: [slides objectAtIndex: index]];
         }
         return self;
     }

    - (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event 
    {    
         //output indices for debugging. (yes, they increment properly)
         NSLog(@"index = %d", index);
         NSLog(@"currentIndex = %d", currentIndex);
         NSLog(@"nextIndex = %d", nextIndex);

         if (nextIndex <= 10) {
           currentIndex = nextIndex;
         } else {
            currentIndex = 0;
         }    
         nextIndex = currentIndex + 1;

         //flipbook - tapping the image transitions to the next image in the array  
         [UIView transitionFromView: [slides objectAtIndex: currentIndex]
                    toView: [slides objectAtIndex: nextIndex]
                    duration: 0
                    options: UIViewAnimationOptionTransitionCurlUp
                    completion: NULL
          ];
     }
4

2 に答える 2

0

AppleのリファレンスによるとUIView: transitionFromView: toView:...

このメソッドは、ビュー階層内のビューのみを変更します。アプリケーションのView Controllerを変更することはありません。たとえば、このメソッドを使用してビュー コントローラーによって表示されるルート ビューを変更する場合、ビュー コントローラーを適切に更新して変更を処理する必要があります。

[yourView setNeedsDisplay]直後にメソッドを呼び出してみてください。

于 2012-04-28T00:11:33.003 に答える