简体   繁体   English

viewDidAppear上的动画UIImageView和UITableView

[英]Animated UIImageView and UITableView on viewDidAppear

I have one UIViewController with my logo centered and UITableView with alpha 0. 我有一个UIViewController ,其徽标居中,而UITableView ,其字母为0。

In viewDidAppear: I have this: viewDidAppear:我有这个:

[UIView animateWithDuration:0.6 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
    [self.logo setFrame:CGRectMake(0.0f, self.view.frame.size.height - 194.0f, 320.0f, 194.0f)];
} completion:^(BOOL finished) {
    [self.table setFrame:CGRectMake(0.0f, 0.0f, 320.0f, self.view.frame.size.height - 194.0f)];

    [UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
        [self.table setAlpha:1.0];
    } completion:^(BOOL finished) {
        return;
    }];

    return;
}];

Ok, the animation is what I want. 好的,动画就是我想要的。

But when I call presentModalViewController: to show next view, UIImageView back to center of screen and UITableView back the the height before. 但是,当我调用presentModalViewController:来显示下一个视图时, UIImageView返回屏幕中心, UITableView返回之前的高度。

How do I stay with the same size and position after finishing the animation even change the view? 完成动画甚至更改视图后,如何保持相同的大小和位置?

Thanks. 谢谢。

I'm assuming you set your original frames in viewDidLoad this is fine unless the modal clears your system memory. 我假设您在viewDidLoad设置了原始帧,除非模式清除了系统内存,否则就可以了。 Views are cached as long as they can. 视图将被尽可能长地缓存。 So if you modal uses enough memory to reset it, viewDidLoad gets called again resetting your view. 因此,如果模态使用足够的内存来重置它,则将再次调用viewDidLoad来重置视图。

A quick and easy way to deal with this is to set the values you want in the dismissViewController:animated: method if you're using it, or a delegate method for the modal. 解决此问题的一种快速简便的方法是,在使用dismissViewController:animated:方法时设置所需的值,或者在模态中使用委托方法。

If you don't have either of those you'll need to do some checking somehow if this is the first load. 如果您没有任何一个,则需要以某种方式进行一些检查,如果这是第一次加载。 This isn't a clean way to deal with it though. 不过,这不是一个干净的方法。 If you show some more code we may be able to work out a better solution. 如果您显示更多代码,我们也许可以找到更好的解决方案。

Note: you're using the wrong options constant. 注意:您使用了错误的选项常量。 Rather than UIViewAnimationCurveEaseInOut , should be using UIViewAnimationOptionCurveEaseInOut . 而不是UIViewAnimationCurveEaseInOut ,应该使用UIViewAnimationOptionCurveEaseInOut That probably doesn't affect your problem, but it is bad. 那可能不会影响您的问题,但这很糟糕。

Also, you don't need return statements in your completion blocks. 同样,您不需要在完成块中使用return语句。

I would check the code in your viewWillDisappear and viewDidDisappear methods. 我会在您的viewWillDisappear和viewDidDisappear方法中检查代码。 It's possible you're doing initial layout in there (or even in layoutSubviews) which is resetting the view. 您可能正在其中进行初始布局(甚至在layoutSubviews中),这将重置视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM