gpt4 book ai didi

ios - 尝试拖放对象时旋转 UIView iOS 错误

转载 作者:行者123 更新时间:2023-11-29 10:49:08 25 4
gpt4 key购买 nike

我有一个用于拖放对象的 UIView 子类,它工作得很好,但在我应用此转换之后

    CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI_2);
self.transform = transform;

当去拖放时,对象开始无限螺旋 :-/

触摸开始

if (!moveObject){

CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI_2);
self.transform = transform;

}else{

// When a touch starts, get the current location in the view
currentPoint = [[touches anyObject] locationInView:self];
}

触摸移动代码在这里

if (moveObject){

//Current point is locationInView get in touchBegin
// Get active location upon move
CGPoint activePoint = [[touches anyObject] locationInView:self];

// Determine new point based on where the touch is now located
CGPoint newPoint = CGPointMake(self.center.x + (activePoint.x - currentPoint.x),
self.center.y + (activePoint.y - currentPoint.y));
// Set new center location
self.center = newPoint;
}

我该如何解决这个问题?

附言moveObject 在别处声明,并正确设置为 YES/NO。


我不想同时移动和旋转对象,每次只做一件事。当我旋转 UIView 时,我想保持一个新的方向,我必须能够以新的方向移动对象。

已添加这是我的 xcode 项目示例。 https://www.dropbox.com/s/lza1n9kjnxa4zun/xcode.zip

最佳答案

我对此进行了测试,它的效果非常好:

- (void)viewDragged:(UIPanGestureRecognizer *)gesture
{

CGPoint translation = [gesture translationInView:self.view];

gesture.view.center = CGPointMake(gesture.view.center.x + translation.x, gesture.view.center.y + translation.y);


[gesture setTranslation:CGPointZero inView:gesture.view];

}

关于ios - 尝试拖放对象时旋转 UIView iOS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21208793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com