Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios [UIView transitionWithView…]的快速系列进展不顺利_Ios_Iphone_Objective C_Uiview_Uiviewanimationtransition - Fatal编程技术网

Ios [UIView transitionWithView…]的快速系列进展不顺利

Ios [UIView transitionWithView…]的快速系列进展不顺利,ios,iphone,objective-c,uiview,uiviewanimationtransition,Ios,Iphone,Objective C,Uiview,Uiviewanimationtransition,我有一个视图,它是一个4x4的图像网格,我试图实现每个正方形的效果,从上到下,从左到右,翻转显示一个新的图像。应该有点“涟漪”效应,所以左上角的方块立即开始翻转,[0,1]方块在0.05秒后翻转,[0,2]在0.10秒后翻转,依此类推,所以在(0.05*15)秒后,最后一个方块开始翻转 我的实现是这样的:每个grid square都是一个UIView子类DMGridSquareView,它包含一个UIImageView和以下方法: - (void)flipToNewImage:(UIImage*

我有一个视图,它是一个4x4的图像网格,我试图实现每个正方形的效果,从上到下,从左到右,翻转显示一个新的图像。应该有点“涟漪”效应,所以左上角的方块立即开始翻转,[0,1]方块在0.05秒后翻转,[0,2]在0.10秒后翻转,依此类推,所以在(0.05*15)秒后,最后一个方块开始翻转

我的实现是这样的:每个grid square都是一个UIView子类DMGridSquareView,它包含一个UIImageView和以下方法:

- (void)flipToNewImage:(UIImage*)img {
    AATileView *mySelf = self;

    [UIView transitionWithView:self.imageView
                      duration:0.4
                       options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
                                  self.imageView.image = img;
                               } completion:^(BOOL finished) {
                                  NSLog(@"Finished flip");
                               }];
}
然后,为了触发DMGridView中所有网格正方形的动画,我将此方法称为:

- (void)flipAllSquares:(NSArray*)newImages {
    int numTiles = self.numColumns * self.numRows;
    for (int idx=0; idx<numTiles; idx++) {
        UIImage *newImg = [newImages objectAtIndex:idx];
        [[self.gridSquareViews objectAtIndex:idx] performSelector:@selector(flipToNewImage:) withObject:newImg afterDelay:(0.05*idx)];
    }
}
-(void)flipAllSquares:(NSArray*)新图像{
int numTiles=self.numColumns*self.numRows;

对于(int idx=0;idx编辑1:

抱歉,看起来我误解了您的问题。您不希望它们一个接一个地翻转,您希望每个视图在上一个视图开始翻转后很快开始翻转

您是否尝试过从完成块递归调用该方法?这样,您就知道只有在上一个图像完成翻转动画后才会调用该方法

NSInteger imageFlipIndex = 0;

- (void)flipToNewImage:(UIImage*)img {
    AATileView *mySelf = self;

    [UIView transitionWithView:self.imageView
                      duration:0.4
                       options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
                                  self.imageView.image = img;
                               } completion:^(BOOL finished) {
                                  imageFlipIndex++;
                                  if (imageFlipIndex < newImages.count) {
                                      UIImage *newImg = [newImages objectAtIndex:idx];
                                      [self flipToNewImage:newImg];
                                  } else {
                                      imageFlipIndex = 0;    
                                  }
                                  NSLog(@"Finished flip");
                               }];
}
NSInteger imageFlipIndex=0;
-(无效)FlipToneImage:(UIImage*)img{
AATileView*我自己=我自己;
[UIView转换WithView:self.imageView
持续时间:0.4
选项:UIViewAnimationOptionTransitionFlipFromLeft动画:^{
self.imageView.image=img;
}完成:^(布尔完成){
imageFlipIndex++;
如果(imageFlipIndex
如果您尝试以下操作,会发生什么情况:

imageFlipIndex++;
if (imageFlipIndex < newImages.count) {
    UIImage *newImg = [newImages objectAtIndex:idx];
    [[self.gridSquareViews objectAtIndex:imageFlipIndex] performSelector:@selector(flipToNewImage:) withObject:newImg afterDelay:(0.05*idx)];
} else {
    imageFlipIndex = 0;    
}
imageFlipIndex++;
如果(imageFlipIndex

在动画块内部?

问题是我不希望它等到上一个动画块完成。它们应该像“波浪”一样快速连续地开始效果。我在发布后意识到了这一点。很抱歉。我一直在思考这一点,真的不知道为什么你在模拟器和设备中得到了不同的结果。更奇怪的是,它突然起作用了。我不相信它,因为我实际上没有更改任何代码…但这里一定发生了一些奇怪的事情。我会再次发布吗如果我注意到其他不寻常的事情…谢谢你让谈话继续进行。如果我发现了什么,我会让你知道。我很好奇到底发生了什么。