详解iOS开发中的转场动画和组动画以及UIView封装动画

2020-01-14 17:05:03于丽

//  YYViewController.m
//  01-uiview封装动画
//
//  Created by apple on 14-6-22.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

 

#import "YYViewController.h"

@interface YYViewController ()
@property (weak, nonatomic) IBOutlet UIView *customView;


@end


复制代码
@implementation YYViewController

 

- (void)viewDidLoad
{
    [super viewDidLoad];
    
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //打印动画块的位置
    NSLog(@"动画执行之前的位置:%@",NSStringFromCGPoint(self.customView.center));
    
    //首尾式动画
    [UIView beginAnimations:nil context:nil];
    //执行动画
    //设置动画执行时间
    [UIView setAnimationDuration:2.0];
    //设置代理
    [UIView setAnimationDelegate:self];
    //设置动画执行完毕调用的事件
    [UIView setAnimationDidStopSelector:@selector(didStopAnimation)];
    self.customView.center=CGPointMake(200, 300);
    [UIView commitAnimations];

}

-(void)didStopAnimation
{
    NSLog(@"动画执行完毕");
    //打印动画块的位置
    NSLog(@"动画执行之后的位置:%@",NSStringFromCGPoint(self.customView.center));
}
@end


执行结果:

 

详解iOS开发中的转场动画和组动画以及UIView封装动画详解iOS开发中的转场动画和组动画以及UIView封装动画