首页 > 其他 > 详细

Core Animation演示

时间:2014-07-11 21:08:25      阅读:455      评论:0      收藏:0      [点我收藏+]

bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣

 

相关代码展示:

- (IBAction)toggleRoundCorners:(id)sender {

    

    [CATransaction setDisableActions:![_enableAnimations isOn]];

    [CATransaction setAnimationDuration:_animationDuration];

    

    [_layer setCornerRadius:([_layer cornerRadius] == 0.0 ? 25.0 : 0.0)];

}

 

- (IBAction)toggleColor:(id)sender {

    [CATransaction setDisableActions:![_enableAnimations isOn]];

    [CATransaction setAnimationDuration:_animationDuration];

    

    [_layer setBackgroundColor:([_layer backgroundColor] == [UIColor blueColor].CGColor ? [UIColor greenColor].CGColor : [UIColor blueColor].CGColor)]; 

}

 

- (IBAction)toggleBorder:(id)sender {

    

    [CATransaction setDisableActions:![_enableAnimations isOn]];

    [CATransaction setAnimationDuration:_animationDuration];

 

    [_layer setBorderWidth:([_layer borderWidth] == 0.0 ? 10 : 0.0)];

}

 

- (IBAction)toggleOpacity:(id)sender {

    

    [CATransaction setDisableActions:![_enableAnimations isOn]];

    [CATransaction setAnimationDuration:_animationDuration];

    

    [_layer setOpacity:([_layer opacity] == 1.0 ? 0.2 : 1.0)];

}

 

- (IBAction)toggleSize:(id)sender 

{

    [CATransaction setDisableActions:![_enableAnimations isOn]];

    [CATransaction setAnimationDuration:_animationDuration];

    

    CGRect layerBounds = _layer.bounds;

    layerBounds.size.width  = (layerBounds.size.width == layerBounds.size.height) ? 250.0 : 200.0;

    [_layer setBounds:layerBounds];

    

    BTSAnchorPointLayer *anchorPointLayer = [[_layer sublayers] objectAtIndex:0];

    [anchorPointLayer setPosition:BTSCalculateAnchorPointPositionForLayer(_layer)];

}

 

 

- (void)beginAnimatingLayer

{

    // Here we are creating an explicit animation for the layer‘s "transform" property.

    // - The duration (in seconds) is controlled by the user.

    // - The repeat count is hard coded to go "forever".

    

    CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];

    [pulseAnimation setDuration:_animationDuration];

    [pulseAnimation setRepeatCount:MAXFLOAT];

    

    // The built-in ease in/ ease out timing function is used to make the animation look smooth as the layer

    // animates between the two scaling transformations.

    [pulseAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    

    // Scale the layer to half the size

    CATransform3D transform = CATransform3DMakeScale(0.50, 0.50, 1.0);

    

    // Tell CA to interpolate to this transformation matrix

    [pulseAnimation setToValue:[NSValue valueWithCATransform3D:CATransform3DIdentity]];

    [pulseAnimation setToValue:[NSValue valueWithCATransform3D:transform]];

    

    // Tells CA to reverse the animation (e.g. animate back to the layer‘s transform)

    [pulseAnimation setAutoreverses:_autoreverses];

    

    // Finally... add the explicit animation to the layer... the animation automatically starts.

    [_layer addAnimation:pulseAnimation forKey:kBTSPulseAnimation];

}

 

- (void)endAnimatingLayer

{

    [_layer removeAnimationForKey:kBTSPulseAnimation];

}

 

Core Animation演示,布布扣,bubuko.com

Core Animation演示

原文:http://www.cnblogs.com/yulang314/p/3833158.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!