简单的翻牌
Posted 潜意识
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单的翻牌相关的知识,希望对你有一定的参考价值。
// // ViewController.m // 翻页测试 // // Created by nyhx on 16/6/29. // Copyright © 2016年 nyhx. All rights reserved. // #import "ViewController.h" #define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI)) #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI) @interface ViewController () { BOOL isAllowButRig; BOOL isAllowTopRig; BOOL isAllowButLef; BOOL isAllowTopLef; BOOL isAllowLef; BOOL isAllowRig; BOOL isAllowTop; BOOL isAllowBut; } @property (weak, nonatomic) IBOutlet UIView *backView; @property (weak, nonatomic) IBOutlet UIImageView *PukeImageView; @property (nonatomic,strong) UIImageView * ZImageView; @property (nonatomic,strong) CAShapeLayer * shapeLayer; @property (nonatomic,strong) CAShapeLayer * BackShapeLayer; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _PukeImageView.image=[UIImage imageNamed:@"back.jpg"]; _ZImageView=[[UIImageView alloc]initWithFrame:_PukeImageView.frame]; _ZImageView.image=[UIImage imageNamed:@"7.jpg"]; [self.backView addSubview:_ZImageView]; //create shape layer _shapeLayer =[CAShapeLayer layer]; _shapeLayer.strokeColor =[UIColor clearColor].CGColor; _shapeLayer.fillColor = [UIColor blueColor].CGColor; _shapeLayer.lineWidth = 1; _shapeLayer.lineJoin = kCALineJoinRound; _shapeLayer.lineCap = kCALineCapRound; _ZImageView.layer.mask=_shapeLayer; //create shape layer _BackShapeLayer =[CAShapeLayer layer]; _BackShapeLayer.strokeColor =[UIColor clearColor].CGColor; _BackShapeLayer.fillColor = [UIColor blueColor].CGColor; _BackShapeLayer.lineWidth = 1; _BackShapeLayer.lineJoin = kCALineJoinRound; _BackShapeLayer.lineCap = kCALineCapRound; _PukeImageView.layer.mask=_BackShapeLayer; //path2 CGPoint point11=CGPointMake(0, 0); CGPoint point22=CGPointMake(_PukeImageView.frame.size.width, 0); CGPoint point33=CGPointMake(_PukeImageView.frame.size.width, _PukeImageView.frame.size.height); CGPoint point44=CGPointMake(0, _PukeImageView.frame.size.height); UIBezierPath *path2 = [[UIBezierPath alloc] init]; [path2 moveToPoint:point11]; [path2 addLineToPoint:point22]; [path2 addLineToPoint:point33]; [path2 addLineToPoint:point44]; [path2 addLineToPoint:point11]; _BackShapeLayer.path = path2.CGPath; } -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { isAllowButRig=NO; isAllowTopRig=NO; isAllowButLef=NO; isAllowTopLef=NO; isAllowLef=NO; isAllowRig=NO; isAllowTop=NO; isAllowBut=NO; CGPoint point=[[touches anyObject] locationInView:self.PukeImageView]; if (point.x>=0&&point.x<self.PukeImageView.frame.size.width/3.0&&point.y>=0&&point.y<self.PukeImageView.frame.size.height/3.0) {//左上角 isAllowTopLef=YES; } if (point.x>=self.PukeImageView.frame.size.width/3.0&&point.x<self.PukeImageView.frame.size.width/3.0*2.0&&point.y>=0&&point.y<self.PukeImageView.frame.size.height/3.0) {//上 isAllowTop=YES; } if (point.x>=self.PukeImageView.frame.size.width/3.0*2.0&&point.x<self.PukeImageView.frame.size.width&&point.y>=0&&point.y<self.PukeImageView.frame.size.height/3.0) {//右上角 isAllowTopRig=YES; } if (point.x>=0&&point.x<self.PukeImageView.frame.size.width/3.0&&point.y>=self.PukeImageView.frame.size.height/3.0&&point.y<self.PukeImageView.frame.size.height/3.0*2.0) {//左 isAllowLef=YES; } if (point.x>=self.PukeImageView.frame.size.width/3.0*2.0&&point.x<self.PukeImageView.frame.size.width&&point.y>=self.PukeImageView.frame.size.height/3.0&&point.y<self.PukeImageView.frame.size.height/3.0*2.0) {//右 isAllowRig=YES; } if (point.x>=0&&point.x<self.PukeImageView.frame.size.width/3.0&&point.y>=self.PukeImageView.frame.size.height/3.0*2.0&&point.y<self.PukeImageView.frame.size.height) {//左下角 isAllowButLef=YES; } if (point.x>=self.PukeImageView.frame.size.width/3.0&&point.x<self.PukeImageView.frame.size.width/3.0*2.0&&point.y>=self.PukeImageView.frame.size.height/3.0*2.0&&point.y<self.PukeImageView.frame.size.height) {//下 isAllowBut=YES; } if (point.x>=self.PukeImageView.frame.size.width/3.0*2.0&&point.x<self.PukeImageView.frame.size.width&&point.y>=self.PukeImageView.frame.size.height/3.0*2.0&&point.y<self.PukeImageView.frame.size.height) {//右下角 isAllowButRig=YES; } } -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { if (isAllowButRig) { _ZImageView.layer.anchorPoint=CGPointMake(0, 1); CGPoint point=[[touches anyObject] locationInView:self.backView]; [self MoveButRigWithPoint:point]; } if (isAllowTopRig) { _ZImageView.layer.anchorPoint=CGPointMake(0, 0); CGPoint point=[[touches anyObject] locationInView:self.backView]; [self MoveTopRigWithPoint:point]; } if (isAllowButLef) { _ZImageView.layer.anchorPoint=CGPointMake(1, 1); CGPoint point=[[touches anyObject] locationInView:self.backView]; [self MoveButLefWithPoint:point]; } if (isAllowTopLef) { _ZImageView.layer.anchorPoint=CGPointMake(1, 0); CGPoint point=[[touches anyObject] locationInView:self.backView]; [self MoveTopLefWithPoint:point]; } if (isAllowLef) { _ZImageView.layer.anchorPoint=CGPointMake(1, 0.5); CGPoint point=[[touches anyObject] locationInView:self.backView]; [self MoveLefWithPoint:point]; } if (isAllowRig) { _ZImageView.layer.anchorPoint=CGPointMake(0, 0.5); CGPoint point=[[touches anyObject] locationInView:self.backView]; [self MoveRigWithPoint:point]; } if (isAllowTop) { _ZImageView.layer.anchorPoint=CGPointMake(0.5, 1); CGPoint point=[[touches anyObject] locationInView:self.backView]; [self MoveTopWithPoint:point]; } if (isAllowBut) { _ZImageView.layer.anchorPoint=CGPointMake(0.5, 0); CGPoint point=[[touches anyObject] locationInView:self.backView]; [self MoveButWithPoint:point]; } } -(void)MoveLefWithPoint:(CGPoint)point { float K=point.x-_PukeImageView.frame.origin.x; if (K<=0) { return; } _ZImageView.layer.position=CGPointMake(_PukeImageView.frame.origin.x+K, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height/2); CGPoint rigPoint2=CGPointMake(_PukeImageView.frame.origin.x+K/2.0, _PukeImageView.frame.origin.y); CGPoint rigPoint3=CGPointMake(_PukeImageView.frame.origin.x+K, _PukeImageView.frame.origin.y); CGPoint rigPoint4=CGPointMake(_PukeImageView.frame.origin.x+K, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); CGPoint rigPoint5=CGPointMake(_PukeImageView.frame.origin.x+K/2.0, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); //path1 [self changeShapeLayerPathWithLayer:_shapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint2],[NSValue valueWithCGPoint:rigPoint3],[NSValue valueWithCGPoint:rigPoint4],[NSValue valueWithCGPoint:rigPoint5]] andConvertView:_ZImageView]; //path2 CGPoint rigPoint11=rigPoint3; CGPoint rigPoint22=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y); CGPoint rigPoint33=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); CGPoint rigPoint44=rigPoint4; [self changeShapeLayerPathWithLayer:_BackShapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint22],[NSValue valueWithCGPoint:rigPoint33],[NSValue valueWithCGPoint:rigPoint44],[NSValue valueWithCGPoint:rigPoint11]] andConvertView:_PukeImageView]; } -(void)MoveRigWithPoint:(CGPoint)point { float K=_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-point.x; if (K<=0) { return; } _ZImageView.layer.position=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-K, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height/2.0); CGPoint rigPoint2=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-K/2.0, _PukeImageView.frame.origin.y); CGPoint rigPoint3=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-K, _PukeImageView.frame.origin.y); CGPoint rigPoint4=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-K, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); CGPoint rigPoint5=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-K/2.0, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); //path1 [self changeShapeLayerPathWithLayer:_shapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint2],[NSValue valueWithCGPoint:rigPoint3],[NSValue valueWithCGPoint:rigPoint4],[NSValue valueWithCGPoint:rigPoint5]] andConvertView:_ZImageView]; //path2 CGPoint rigPoint11=rigPoint3; CGPoint rigPoint22=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y); CGPoint rigPoint33=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); CGPoint rigPoint44=rigPoint4; [self changeShapeLayerPathWithLayer:_BackShapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint22],[NSValue valueWithCGPoint:rigPoint33],[NSValue valueWithCGPoint:rigPoint44],[NSValue valueWithCGPoint:rigPoint11]] andConvertView:_PukeImageView]; } -(void)MoveTopWithPoint:(CGPoint)point { float K=point.y-_PukeImageView.frame.origin.y; if (K<=0) { return; } _ZImageView.layer.position=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width/2.0, _PukeImageView.frame.origin.y+K); CGPoint rigPoint2=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+K/2.0); CGPoint rigPoint3=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+K); CGPoint rigPoint4=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+K); CGPoint rigPoint5=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+K/2.0); //path1 [self changeShapeLayerPathWithLayer:_shapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint2],[NSValue valueWithCGPoint:rigPoint3],[NSValue valueWithCGPoint:rigPoint4],[NSValue valueWithCGPoint:rigPoint5]] andConvertView:_ZImageView]; //path2 CGPoint rigPoint11=rigPoint3; CGPoint rigPoint22=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); CGPoint rigPoint33=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); CGPoint rigPoint44=rigPoint4; [self changeShapeLayerPathWithLayer:_BackShapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint22],[NSValue valueWithCGPoint:rigPoint33],[NSValue valueWithCGPoint:rigPoint44],[NSValue valueWithCGPoint:rigPoint11]] andConvertView:_PukeImageView]; } -(void)MoveButWithPoint:(CGPoint)point { float K=_PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-point.y; if (K<=0) { return; } _ZImageView.layer.position=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width/2.0, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-K); CGPoint rigPoint2=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-K/2.0); CGPoint rigPoint3=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-K); CGPoint rigPoint4=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-K); CGPoint rigPoint5=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-K/2.0); //path1 [self changeShapeLayerPathWithLayer:_shapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint2],[NSValue valueWithCGPoint:rigPoint3],[NSValue valueWithCGPoint:rigPoint4],[NSValue valueWithCGPoint:rigPoint5]] andConvertView:_ZImageView]; //path2 CGPoint rigPoint11=rigPoint3; CGPoint rigPoint22=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y); CGPoint rigPoint33=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y); CGPoint rigPoint44=rigPoint4; [self changeShapeLayerPathWithLayer:_BackShapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint22],[NSValue valueWithCGPoint:rigPoint33],[NSValue valueWithCGPoint:rigPoint44],[NSValue valueWithCGPoint:rigPoint11]] andConvertView:_PukeImageView]; } #pragma ---角 -(void)MoveTopLefWithPoint:(CGPoint)point { float K=point.x-_PukeImageView.frame.origin.x; float L=point.y-_PukeImageView.frame.origin.y; if (K<=0||L<=0) { return; } float bianX=(K*K+L*L)/(2*K); float HuduCos1=(K-bianX)/bianX;//角1cos弧度 CGPoint rigPoint2=CGPointZero; CGPoint rigPoint3=CGPointZero; if (RADIANS_TO_DEGREES(acosf(HuduCos1))<90.0) {//情况1 float bianY=K/L*bianX; _ZImageView.layer.position=point; _ZImageView.layer.transform=CATransform3DMakeRotation(acosf(HuduCos1), 0, 0, 1);//正面旋转 rigPoint2=CGPointMake(_PukeImageView.frame.origin.x+bianX, _PukeImageView.frame.origin.y) ; rigPoint3=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+bianY); } else{//情况2 float bianY=(K*K+L*L)/(2*L); bianX=L/K*bianY; _ZImageView.layer.position=point; _ZImageView.layer.transform=CATransform3DMakeRotation(acosf(HuduCos1), 0, 0, 1);//正面旋转 rigPoint2=CGPointMake(_PukeImageView.frame.origin.x+bianX, _PukeImageView.frame.origin.y) ; rigPoint3=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+bianY); } //path1 [self changeShapeLayerPathWithLayer:_shapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint2],[NSValue valueWithCGPoint:rigPoint3],[NSValue valueWithCGPoint:point]] andConvertView:_ZImageView]; //path2 CGPoint rigPoint11=rigPoint2; CGPoint rigPoint22=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y); CGPoint rigPoint33=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); CGPoint rigPoint44=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); CGPoint rigPoint55=rigPoint3; [self changeShapeLayerPathWithLayer:_BackShapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint22],[NSValue valueWithCGPoint:rigPoint33],[NSValue valueWithCGPoint:rigPoint44],[NSValue valueWithCGPoint:rigPoint55],[NSValue valueWithCGPoint:rigPoint11]] andConvertView:_PukeImageView]; } -(void)MoveButLefWithPoint:(CGPoint)point { float K=point.x-_PukeImageView.frame.origin.x; float L=_PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-point.y; if (K<=0||L<=0) { return; } float bianX=(K*K+L*L)/(2*K); float HuduCos1=(K-bianX)/bianX;//角1cos弧度 CGPoint rigPoint2=CGPointZero; CGPoint rigPoint3=CGPointZero; if (RADIANS_TO_DEGREES(acosf(HuduCos1))<90.0) {//情况1 float bianY=K/L*bianX; _ZImageView.layer.position=point; _ZImageView.layer.transform=CATransform3DMakeRotation(acosf(HuduCos1), 0, 0, -1);//正面旋转 rigPoint2=CGPointMake(_PukeImageView.frame.origin.x+bianX, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height) ; rigPoint3=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-bianY); } else{//情况2 float bianY=(K*K+L*L)/(2*L); bianX=L/K*bianY; _ZImageView.layer.position=point; _ZImageView.layer.transform=CATransform3DMakeRotation(DEGREES_TO_RADIANS(180.0-RADIANS_TO_DEGREES(asinf(K/bianY))), 0, 0, -1);//正面旋转 rigPoint2=CGPointMake(_PukeImageView.frame.origin.x+bianX, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height) ; rigPoint3=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-bianY); } //path1 [self changeShapeLayerPathWithLayer:_shapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint2],[NSValue valueWithCGPoint:rigPoint3],[NSValue valueWithCGPoint:point]] andConvertView:_ZImageView]; //path2 CGPoint rigPoint11=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y); CGPoint rigPoint22=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y); CGPoint rigPoint33=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); CGPoint rigPoint44=rigPoint2; CGPoint rigPoint55=rigPoint3; [self changeShapeLayerPathWithLayer:_BackShapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint22],[NSValue valueWithCGPoint:rigPoint33],[NSValue valueWithCGPoint:rigPoint44],[NSValue valueWithCGPoint:rigPoint55],[NSValue valueWithCGPoint:rigPoint11]] andConvertView:_PukeImageView]; } -(void)MoveTopRigWithPoint:(CGPoint)point { float K=_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-point.x; float L=point.y-_PukeImageView.frame.origin.y; if (K<=0||L<=0) { return; } float bianX=(K*K+L*L)/(2*K); float HuduCos1=(K-bianX)/bianX;//角1cos弧度 CGPoint rigPoint2=CGPointZero; CGPoint rigPoint3=CGPointZero; if (RADIANS_TO_DEGREES(acosf(HuduCos1))<90.0) {//情况1 float bianY=K/L*bianX; _ZImageView.layer.position=point; _ZImageView.layer.transform=CATransform3DMakeRotation(acosf(HuduCos1), 0, 0, -1);//正面旋转 rigPoint2=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-bianX, _PukeImageView.frame.origin.y) ; rigPoint3=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+bianY); } else{//情况2 float bianY=(K*K+L*L)/(2*L); bianX=L/K*bianY; _ZImageView.layer.position=point; _ZImageView.layer.transform=CATransform3DMakeRotation(acosf(HuduCos1), 0, 0, -1);//正面旋转 rigPoint2=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-bianX, _PukeImageView.frame.origin.y) ; rigPoint3=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+bianY); } //path1 [self changeShapeLayerPathWithLayer:_shapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint2],[NSValue valueWithCGPoint:rigPoint3],[NSValue valueWithCGPoint:point]] andConvertView:_ZImageView]; //path2 CGPoint rigPoint11=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y); CGPoint rigPoint22=rigPoint2; CGPoint rigPoint33=rigPoint3; CGPoint rigPoint44=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); CGPoint rigPoint55=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); [self changeShapeLayerPathWithLayer:_BackShapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint22],[NSValue valueWithCGPoint:rigPoint33],[NSValue valueWithCGPoint:rigPoint44],[NSValue valueWithCGPoint:rigPoint55],[NSValue valueWithCGPoint:rigPoint11]] andConvertView:_PukeImageView]; } -(void)MoveButRigWithPoint:(CGPoint)point { float K=_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-point.x; float L=_PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-point.y; if (K<=0||L<=0) { return; } float bianX=(K*K+L*L)/(2*K); float HuduCos1=(K-bianX)/bianX;//角1cos弧度 CGPoint rigPoint2=CGPointZero; CGPoint rigPoint3=CGPointZero; if (RADIANS_TO_DEGREES(acosf(HuduCos1))<90.0) {//情况1 float bianY=K/L*bianX; _ZImageView.layer.position=point; _ZImageView.layer.transform=CATransform3DMakeRotation(acosf(HuduCos1), 0, 0, 1);//正面旋转 rigPoint2=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-bianX, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height) ; rigPoint3=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-bianY); } else{//情况2 float bianY=(K*K+L*L)/(2*L); bianX=L/K*bianY; _ZImageView.layer.position=point; _ZImageView.layer.transform=CATransform3DMakeRotation(DEGREES_TO_RADIANS(180.0-RADIANS_TO_DEGREES(asinf(K/bianY))), 0, 0, 1);//正面旋转 rigPoint2=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width-bianX, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height) ; rigPoint3=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height-bianY); } //path1 [self changeShapeLayerPathWithLayer:_shapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint2],[NSValue valueWithCGPoint:rigPoint3],[NSValue valueWithCGPoint:point]] andConvertView:_ZImageView]; //path2 CGPoint rigPoint11=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y); CGPoint rigPoint22=CGPointMake(_PukeImageView.frame.origin.x+_PukeImageView.frame.size.width, _PukeImageView.frame.origin.y); CGPoint rigPoint33=rigPoint3; CGPoint rigPoint44=rigPoint2; CGPoint rigPoint55=CGPointMake(_PukeImageView.frame.origin.x, _PukeImageView.frame.origin.y+_PukeImageView.frame.size.height); [self changeShapeLayerPathWithLayer:_BackShapeLayer andArr:@[[NSValue valueWithCGPoint:rigPoint22],[NSValue valueWithCGPoint:rigPoint33],[NSValue valueWithCGPoint:rigPoint44],[NSValue valueWithCGPoint:rigPoint55],[NSValue valueWithCGPoint:rigPoint11]] andConvertView:_PukeImageView]; } -(void)changeShapeLayerPathWithLayer:(CAShapeLayer *)layer andArr:(NSArray *)arr andConvertView:(UIImageView *)convertView { NSValue * lastValue=[arr lastObject]; UIBezierPath *path = [[UIBezierPath alloc] init]; [path moveToPoint:[self.backView convertPoint:[lastValue CGPointValue] toView:convertView]]; for (NSValue * value in arr) { CGPoint point=[self.backView convertPoint:[value CGPointValue] toView:convertView]; [path addLineToPoint:point]; } layer.path=path.CGPath; } -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSLog(@"111"); } @end
以上是关于简单的翻牌的主要内容,如果未能解决你的问题,请参考以下文章
新星计划python赛道pygame实现翻牌游戏的豆腐块,豆腐块也有春天
新星计划python赛道pygame实现翻牌游戏的豆腐块,豆腐块也有春天
新星计划python赛道pygame实现翻牌游戏的豆腐块,豆腐块也有春天