上次说了一下mask,这次来讲一下如何用mask来实现这个动画,关于自定义转场动画的内容可以查看这篇文章,要实现的动画如下:
首页实现两个viewcontroller之间的push和pop,示例代码如下:
第一个viewcontroller
- (void)viewDidLoad {
[super viewDidLoad];
//设置背景色
self.view.backgroundColor = [UIColor greenColor];
//放一张图片
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
imageView.center = self.view.center;
imageView.image = [UIImage imageNamed:@"ipad.jpg"];
[self.view addSubview:imageView];
//创建按钮
_btn = [UIButton buttonWithType:UIButtonTypeCustom];
_btn.backgroundColor = [UIColor blackColor];
_btn.layer.cornerRadius = 22;
_btn.frame = CGRectMake(self.view.frame.size.width-20-44, 20, 44, 44);
[_btn addTarget:self action:@selector(goNext) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_btn];
}
//push到下一个
- (void)goNext
{
SecondViewController *sec = [[SecondViewController alloc]init];
[self.navigationController pushViewController:sec animated:YES];
}
第二个viewcontroller: