动画执行时调用的方法[UIView beginAnimations: context:];

@implementation ViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    UIImageView * iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];

    iv.image = [UIImage imageNamed:@"moji"];

    [self.view addSubview:iv];

    

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDelegate:self];

    [UIView setAnimationWillStartSelector:@selector(animationDidStart:)];

    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];

    [UIView setAnimationDelay:0.0f];

    [UIView setAnimationDuration:1.0f];

    

    iv.alpha = 0.0f;

    [UIView commitAnimations];

    //[iv release];


}


-(void)animationDidStart:(CAAnimation *)anim

{

    NSLog(@"animation is start ...");

}


-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag

{

    NSLog(@"animation is over ...");

}

@end

如上是规范的写法:

注意:

1、一定要写[UIView beginAnimations:nil context:nil];

2、一定要设置代理 因为后两者本质是协议方法

3、要设置选择器[UIView setAnimationWillStartSelector:@selector(animationDidStart:)];

有时候,你不设置选择器,只是设置了代理 如果你实现了 协议中的开始和停止方法,那么程序会执行stop方法,但是不会执行DidStart方法。

为了规范起见,要设置选择器。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值