一个滑出view 的动画

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_30190885/article/details/49781615
#import "ViewController.h"
#define width ([UIScreen mainScreen].bounds.size.width)
#define height ([UIScreen mainScreen].bounds.size.height)
@interface ViewController ()
@property(nonatomic, strong)UIView *rightview;
@property(nonatomic, assign)NSInteger index;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor cyanColor];
    self.rightview = [[UIView alloc] init];
    self.rightview.frame = self.view.frame;
    self.rightview.center = CGPointMake(1.5 * width, height/2);
    self.rightview.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.rightview];
    
    UIGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(press)];
    [self.view addGestureRecognizer:gesture];
    
}

//
- (void)press{
   
    //out
    
    if (self.index%2 == 1) {
        [UIView beginAnimations:@"23" context:nil];
        [UIView setAnimationDuration:1];
        self.rightview.center = CGPointMake(width*3/4, height/2);
        [UIView commitAnimations];
    }else{
        [UIView beginAnimations:@"123" context:nil];
        [UIView setAnimationDuration:1];
        self.rightview.center = CGPointMake(1.5 * width, height/2);
        [UIView commitAnimations];
    }
    
     self.index++;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

猜你喜欢

转载自blog.csdn.net/sinat_30190885/article/details/49781615