UIView 的transitionFromView方法实现视图切换

时间:2022-03-16 10:43:50
#import "ViewController.h"

@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIImageView *imageViewFirst;
@property (strong, nonatomic) IBOutlet UIImageView *imageViewSecond;
@property(nonatomic,assign)__block BOOL rectToVisible;
@end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad];
_rectToVisible=YES;
[self.view addSubview:_imageViewFirst]; }
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_rectToVisible) { [UIView transitionFromView:self.imageViewFirst toView:self.imageViewSecond duration: options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) { NSLog(@"animatioin complete");
_rectToVisible=!_rectToVisible; }];
}
else
{
[UIView transitionFromView:self.imageViewSecond toView:self.imageViewFirst duration: options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) { NSLog(@"animatioin complete");
_rectToVisible=!_rectToVisible; }];
} } @end