ios仿照京東點擊出現(xiàn)收貨地址的動畫

主要用到的方法是UIView animation和3D效果主要的代碼如下

1.創(chuàng)建背景的view給View添加手勢

- (void)viewDidLoad {

[super viewDidLoad];

UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

view.backgroundColor = [UIColor redColor];

self.myView = view;

[self.myView setUserInteractionEnabled:YES];

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapped:)];

[view addGestureRecognizer:tap];

[self.view addSubview:view];

}

2.添加3D效果的動畫

-(CATransform3D)firstTransform{

CATransform3D t1 = CATransform3DIdentity;

t1.m34 = 1.0/-900;

t1 = CATransform3DScale(t1, 0.95, 0.95, 1);

//繞x旋轉(zhuǎn)

t1 = CATransform3DRotate(t1, 15.0*M_PI/180.0, 1, 0, 0);

return t1;

}

-(void)tapped:(UITapGestureRecognizer *)tap{

[UIView animateWithDuration:0.3 animations:^{

[self.myView.layer setTransform:[self firstTransform]];

UIView * all = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.bounds.size.height, [UIScreen mainScreen].bounds.size.width, 400)];

self.allView = all;

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];

[all addGestureRecognizer:tap];

all.backgroundColor = [UIColor yellowColor];

UIWindow * window = [[UIApplication sharedApplication].windows lastObject];

[window addSubview:all];

}completion:^(BOOL finished) {

[UIView animateWithDuration:0.3 animations:^{

//縮小紅色View的面積并且改變黃色View的Y值

self.myView.transform = CGAffineTransformMakeScale(0.9, 0.95);

self.allView.frame = CGRectMake(0, self.view.bounds.size.height - 400, [UIScreen mainScreen].bounds.size.width, 400);

} completion:^(BOOL finished) {

}];

}];

}

#pragma mark---點擊歸為

- (CATransform3D)firstTransfrom3{

CATransform3D t1 = CATransform3DIdentity;

t1.m34 = 1.0/-00;

t1 = CATransform3DScale(t1, 1, 1, 1);

t1 = CATransform3DRotate(t1, 15*M_PI/180.0, 1, 0, 0);

return t1;

}

- (void)tap:(UITapGestureRecognizer *)tap{

[UIView animateWithDuration:0.3 animations:^{

self.allView.frame = CGRectMake(0, self.view.frame.size.height, [UIScreen mainScreen].bounds.size.width, 400);

[self.myView.layer setTransform:[self firstTransfrom3]];

} completion:^(BOOL finished) {

[self.allView removeFromSuperview];

[UIView animateWithDuration:0.3 animations:^{

self.myView.transform = CGAffineTransformMakeScale(1, 1);

}];

}];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容