一个View,两个背景色,交替出现:
#import "ViewController.h"
@interface ViewController ()
{
UIView *_contentView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_contentView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 300, 300)];
_contentView.backgroundColor = [UIColor redColor];
[self.view addSubview:_contentView];
self.view.backgroundColor = [UIColor blackColor];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[UIView transitionWithView:_contentView
duration:1
options:UIViewAnimationOptionTransitionFlipFromBottom|UIViewAnimationOptionAllowAnimatedContent
animations:^{
if(_contentView.backgroundColor == [UIColor blueColor]){
_contentView.backgroundColor = [UIColor redColor];
} else {
_contentView.backgroundColor = [UIColor blueColor];
}
} completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end