简单的界面淡入淡出的效果--------主要的实现思路是改变界面的透明度
- (void)viewDidLoad {
[super viewDidLoad];
//要弹出的界面
UIView *testView = [[UIView alloc] initWithFrame:self.view.frame];
testView.backgroundColor = [UIColor blueColor];
testView.tag = 1000;
[self.view addSubview:testView];
testView.alpha = 0.0;
//创建当前界面点击手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test)];
[self.view addGestureRecognizer:tap];
//创建淡出界面的点击手势
UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test2)];
[testView addGestureRecognizer:tap2];
}
实现方法
- (void)test{
//改变透明度即可实现效果
[UIView animateWithDuration:0.5 animations:^{
UIView *view = [self.view viewWithTag:1000];
view.alpha = 1.0;
[self.view layoutIfNeeded];
}];
}
- (void)test2{
[UIView animateWithDuration:0.5 animations:^{
UIView *view = [self.view viewWithTag:1000];
view.alpha = 0.0;
[self.view layoutIfNeeded];
}];
}
还有一种最简单的方式是:
[UIView transitionWithView:self.view duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.view.backgroundColor = [UIColor redColor];
} completion:nil];