【问题标题】:UIView animateWithDuration not animating in ios8UIView animateWithDuration 在 ios8 中没有动画
【发布时间】:2014-10-09 11:20:41
【问题描述】:

我已经实现了一个自定义 segue 类来模拟没有导航栏的推送转换。诀窍是拍摄快照,将它们添加到视图中,替换 viewController,移动快照,最后删除它们。这模拟了 viewController 的水平移动,但实际上只移动了两个 UIImagesView。

以下代码实现了这一点。

self.destinationImageView.frame = offsetFrameD;
self.sourceImageView.frame = offsetFrameS;

//ViewController replacement
[self.sourceViewController presentModalViewController:self.destinationViewController animated:NO];

//Overpose the snapShot who will simulate the transition between vies.
[destinationView addSubview: self.sourceImageView];
[destinationView addSubview: self.destinationImageView];

[UIView animateWithDuration:1.0
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     self.destinationImageView.frame = self.finalFrameD;
                     self.sourceImageView.frame = self.finalFrameS;
                 }
                 completion:^(BOOL finished) {
                     [self.sourceImageView removeFromSuperview];
                     [self.destinationImageView removeFromSuperview];
                 }];

此代码适用于 iOS 7。但是,在使用 iOS 8 时,似乎没有执行动画。 destinationImageView 和 sourceImageView 直接移动到 finalPosition(WITHOUT ANIMATING)并且没有调用完成块,所以最终都没有移除 UIImageView。

有谁知道应该如何在 iOS 8 中执行动画?

【问题讨论】:

标签: ios objective-c iphone animation quartz-core


【解决方案1】:

您应该调整自动布局约束而不是框架位置。看看这个解决方案。我希望它有所帮助。 UIView transitionWithView & setting the frame no longer works iOS8

【讨论】:

    【解决方案2】:

    在动画开始前使用以下代码行:

    [UIView setAnimationsEnabled:YES];
    

    【讨论】:

    • 在动画开始前使用这行代码写下这行代码。
    • [UIView setAnimationsEnabled:YES]; [UIView animateWithDuration:3.0 动画:^{ } 完成:^(BOOL 完成) { }];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    相关资源
    最近更新 更多