xcode 如何使用动画取消隐藏视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7060070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:04:00  来源:igfitidea点击:

How to unhide view with animations

iphonexcodecocoa-touch

提问by Snowman

Say I have a hidden view in Xcode for iOS. Now, when I set the view to not hidden (view.hidden=NO), how can I make it so that it now appears, but with animations?

假设我在 Xcode for iOS 中有一个隐藏视图。现在,当我将视图设置为不隐藏(view.hidden=NO)时,我怎样才能让它现在出现,但带有动画?

回答by mrueg

What you probably want is not to set view.hidden, but to set view.alphato 0(corresponds to hidden = YES) or 1 (hidden = NO).

您可能想要的不是设置view.hidden,而是设置view.alpha0(对应于hidden = YES)或 1 ( hidden = NO)。

You can then use implicit animations to show the view, e.g

然后您可以使用隐式动画来显示视图,例如

[UIView animateWithDuration:0.3 animations:^() {
    view.alpha = 1.0;
}];

回答by Abhi

If you want other animations than only fading then use this method

如果您想要其他动画而不仅仅是淡入淡出,请使用此方法

[UIView transitionWithView:_yourView duration:1.0 options:UIViewAnimationOptionTransitionCurlDown animations:^(void){

            [_yourView setHidden:NO];

        } completion:nil];

回答by Benjamin Mayo

For a fade, you can adjust the alpha property of the view.

对于淡入淡出,您可以调整视图的 alpha 属性。

myView.alpha = 0;
[UIView animateWithDuration:0.5 animations:^{
    myView.alpha = 1;
}];

That will apply a fade in over 0.5 seconds to the view myView. Many UIView properties are animatable; you aren't just limited to alpha fades. You can change background colours, or even rotate and scale a view, with animation. If you need further control and advanced animation, you can then move into Core Animation - a much more complex animation framework.

这将在 0.5 秒内对视图应用淡入淡出myView。许多 UIView 属性是可动画的;您不仅限于 alpha 淡入淡出。您可以使用动画更改背景颜色,甚至旋转和缩放视图。如果您需要进一步的控制和高级动画,您可以进入 Core Animation——一个更复杂的动画框架。

回答by Praveen-K

-(void)showView{

  [UIView beginAnimations: @"Fade Out" context:nil];
  [UIView setAnimationDelay:0];
  [UIView setAnimationDuration:.5];
  //show your view with Fade animation lets say myView
  [myView setHidden:FALSE];
  [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(hideView) userInfo:nil repeats:YES];

  [UIView commitAnimations];
}


-(void)hideView{
  [UIView beginAnimations: @"Fade In" context:nil];
  [UIView setAnimationDelay:0];
  [UIView setAnimationDuration:.5];
  //hide your view with Fad animation
  [myView setHidden:TRUE];
  [UIView commitAnimations];
}

OR you can try this way

或者你可以试试这种方式

self.yourView.alpha = 0.0;
[UIView beginAnimations:@"Fade-in" context:NULL];
[UIView setAnimationDuration:1.0];
self.yourView.alpha = 1.0;
[UIView commitAnimations];