UIView动画例子实践

淡入淡出效果的例子,其中对象关系图:
SampleAppDelegate
    HelloController init
        ToggleView init
            UIImageView init
            self addSubview
            UIImageView release
        ToggleView release
其它对象释放

关于淡入淡出的事件触发放在ToggleView的touchesBegan事件,实现的是对ToggleView本身的动画,从而达到对子视图UIImageView的淡出淡入的效果的控制,而UIImageView视图作为子视图不允许发生触摸交换(imgView.userInteractionEnabled = NO;),仅控制自身的显示情况

现在学习下UIView的新方法,下面是淡入淡出效果实现;
// perform the fade out or fade in
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:
1.0];
[[self viewWithTag:IMAGE_VIEW_TAG] setAlpha:(
float)isVisible];//注意,这个对当前子视图设置显示属性
[UIView commitAnimations];


UIView类

类方法:(动画部分)
beginAnimations:context:
    + (void)beginAnimations:(NSString *)animationID context:(void *)context

    Marks the beginning of a begin/commit animation block.

setAnimationCurve:
    + (void)setAnimationCurve:(UIViewAnimationCurve)curve

    Sets the curve to use when animating property changes within an animation block.

setAnimationDuration:
    + (void)setAnimationDuration:(NSTimeInterval)duration

    Sets the duration (measured in seconds) of the animations in an animation block.

commitAnimations
    + (void)commitAnimations

    Marks the end of a begin/commit animation block and schedules the animations for execution.

Constants/常量
UIViewAnimationCurveEaseInOut
    An option for specifying an ease-in ease-out timing curve for the animation. An ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of its duration, and then slow again before completing. This is the default curve for most animations.

UIViewAnimationCurveEaseIn
    An option for specifying an ease-in timing curve for the animation. An ease-in curve causes the animation to begin slowly, and then speed up as it progresses.

UIViewAnimationCurveEaseOut
    An option for specifying an ease-out timing curve for the animation. An ease-out curve causes the animation to begin quickly, and then slow down as it finishes.

UIViewAnimationCurveLinear
    An option for specifying a linear timing curve for the animation. A linear animation curve causes an animation to occur evenly over its duration.






posted @ 2011-05-20 14:38  西就东城  阅读(2563)  评论(0编辑  收藏  举报