用CGAffineTransformMakeRotation旋转横屏后,平移的问题,可以加这段代码
Jijingcheng opened this issue · comments
Jijingcheng commented
/**
拖动事件
@param pan 拖动手势
*/
-(void)dragAction:(UIPanGestureRecognizer *)pan{
if(self.dragEnable==NO)return;
switch (pan.state) {
case UIGestureRecognizerStateBegan:{//开始拖动
if (self.beginDragBlock) {
self.beginDragBlock(self);
}
//注意完成移动后,将translation重置为0十分重要。否则translation每次都会叠加
[pan setTranslation:CGPointZero inView:self];
//保存触摸起始点位置
self.startPoint = [pan translationInView:self];
break;
}
case UIGestureRecognizerStateChanged:{//拖动中
//计算位移 = 当前位置 - 起始位置
if (self.duringDragBlock) {
self.duringDragBlock(self);
}
CGPoint point = [pan translationInView:self];
float dx;
float dy;
switch (self.dragDirection) {
case WMDragDirectionAny:
{
if (self.isXuanHeng) {
dy = point.x - self.startPoint.x;
dx = self.startPoint.y - point.y;
} else {
dx = point.x - self.startPoint.x;
dy = point.y - self.startPoint.y;
}
}
break;
case WMDragDirectionHorizontal:
dx = point.x - self.startPoint.x;
dy = 0;
break;
case WMDragDirectionVertical:
dx = 0;
dy = point.y - self.startPoint.y;
break;
default:
dx = point.x - self.startPoint.x;
dy = point.y - self.startPoint.y;
break;
}
//计算移动后的view中心点
CGPoint newCenter = CGPointMake(self.center.x + dx, self.center.y + dy);
//移动view
self.center = newCenter;
// 注意完成上述移动后,将translation重置为0十分重要。否则translation每次都会叠加
[pan setTranslation:CGPointZero inView:self];
break;
}
case UIGestureRecognizerStateEnded:{//拖动结束
[self keepBounds];
if (self.endDragBlock) {
self.endDragBlock(self);
}
break;
}
default:
break;
}
}