How to unhide view with animations

后端 未结 4 708
孤街浪徒
孤街浪徒 2021-02-19 03:47

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?

4条回答
  •  深忆病人
    2021-02-19 03:57

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

    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.

提交回复
热议问题