iOS开发 仿淘宝,京东商品详情3D动画

时间:2022-06-24 17:55:20

- (void)show {

[[UIApplication sharedApplication].windows[0] addSubview:self.projectView];

CGRect frame = self.projectView.frame;

frame.origin.y = fView_Height(self.view) - 480*DY_Proportion;

@weakify(self)

[UIView animateWithDuration:0.25 animations:^{

@strongify(self)

[self.groundView.layer setTransform:[self firstTransform]];//红色view调用了上面的旋转效果

} completion:^(BOOL finished) {

@strongify(self)

[UIView animateWithDuration:0.25 animations:^{

@strongify(self)

//旋转完成以后页面缩小 同事改变黄色页面的frame的y值

[self.groundView.layer setTransform:[self secondTransform]];

//显示maskView

[self.maskView setAlpha:0.5f];

//popView上升

self.projectView.frame = frame;

} ];

}];

}

- (void)close {

CGRect frame = self.projectView.frame;

frame.origin.y = fView_Height(self.view) + 30*DY_Proportion;

@weakify(self)

[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

@strongify(self)

//maskView隐藏

[self.maskView setAlpha:0.f];

//popView下降

self.projectView.frame = frame;

//同时进行 感觉更丝滑

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

} completion:^(BOOL finished) {

@strongify(self)

[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

@strongify(self)

//变为初始值

[self.groundView.layer setTransform:CATransform3DIdentity];

} completion:^(BOOL finished) {

@strongify(self)

//移除

[self.projectView removeFromSuperview];

}];

}];

}

- (CATransform3D)firstTransform{

CATransform3D t1 = CATransform3DIdentity;

t1.m34 = 1.0/-900;

//带点缩小的效果

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

//绕x轴旋转

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

return t1;

}

- (CATransform3D)secondTransform{

CATransform3D t2 = CATransform3DIdentity;

t2.m34 = [self firstTransform].m34;

//向下移

t2 = CATransform3DTranslate(t2, 0, 0, 0);

//第二次缩小

t2 = CATransform3DScale(t2, 0.90, 0.90, 1);

return t2;

}