iOS翻书动画
// 翻书效果
UIImage *image = [UIImage imageNamed:@"pic_1"];
CGSize size = [Math resetFromSize:image.size withFixedWidth:self.view.width/2.f];
// layer
_layer = [CALayer layer];
_layer.anchorPoint = CGPointMake(1.f, 0.5f);
_layer.frame = CGRectMake(0, 0, self.view.width/2, size.height);
_layer.position = CGPointMake(self.view.width/2, self.contentView.middleY);
_layer.contents = (__bridge id)([UIImage imageNamed:@"pic_1"].CGImage);
_layer.borderColor = [UIColor blackColor].CGColor;
_layer.borderWidth = 4.f;
_layer.masksToBounds = YES;
_layer.allowsEdgeAntialiasing = YES; // 抗锯齿
_layer.transform = CATransform3DMakeRotation([Math radianFromDegree:0], 0.0, 1.0, 00);
//_layer.transform = catransform3d
[self.contentView.layer addSublayer:_layer];
// 一元一次方程
self.math = [Math mathOnceLinearEquationWithPointA:MATHPointMake(0,0) PointB:MATHPointMake(self.view.width,180)];
//手势
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:pan];
- (void)handlePan:(UIPanGestureRecognizer *)sender {
CGPoint curPoint = [sender locationInView:sender.view];
CGFloat x = curPoint.x;
// 初始化3D变换,获取默认值
CATransform3D perspectiveTransform = CATransform3DIdentity;
//透视
perspectiveTransform.m34 = -1.0/2000.0;
// 空间旋转
perspectiveTransform = CATransform3DRotate(perspectiveTransform, [Math radianFromDegree:x * self.math.k], 0, 1, 0);
[CATransaction setDisableActions:YES];
_layer.transform = perspectiveTransform;
_layer.contents = (__bridge id)([UIImage imageNamed:x >= self.view.width/2.0f ? @"pic_2" : @"pic_1"].CGImage);
if (sender.state == UIGestureRecognizerStateEnded) {
// 初始化3D变换,获取默认值
CATransform3D perspectiveTransform = CATransform3DIdentity;
// 透视
perspectiveTransform.m34 = -1.0/2000.0;
// 空间旋转
perspectiveTransform = CATransform3DRotate(perspectiveTransform, [Math radianFromDegree:x >= self.view.width/2.0f ? 180 : 0], 0, 1, 0);
[CATransaction setDisableActions:NO];
_layer.transform = perspectiveTransform;
}
【iOS翻书动画】}最后demo地址翻书效果
文章图片
推荐阅读
- 2020-04-07vue中Axios的封装和API接口的管理
- iOS中的Block
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- 2019-08-29|2019-08-29 iOS13适配那点事
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- iOS面试题--基础
- 2018-04-16动画练习作业
- 接口|axios接口报错-参数类型错误解决
- iOS|iOS 笔记之_时间戳 + DES 加密
- iOS,打Framework静态库