使用CGAffineTransformMakeRotation时抖动

时间:2011-11-19 21:26:22

标签: iphone objective-c ios

使用CGAffineTransformMakeRotation我遇到了跳跃运动的问题。它似乎工作正常,直到我到达象限1和2的顶部。下面是我正在使用的代码和youtube链接,显示发生了什么。任何见解都会非常感激。

我的目标是在内部使用svg旋转UIWebView。由于我无法单独检测UIWebView上的触摸,因此我在其上放置了一个空白的UIImageView。这允许我检测触摸并防止弹出复制对话框。

http://www.youtube.com/watch?v=x_OmS0MPdEE&feature=youtu.be

    - (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
NSArray *allTouches = [touches allObjects]; 
CGPoint location = [[allTouches objectAtIndex:0] locationInView:self.view];
if(selected == 1) {
    CGFloat rads = atan2f(location.y - (grid1.frame.size.height/2),location.x - (grid1.frame.size.width/2));
    grid1.transform = grid1Btn.transform = CGAffineTransformMakeRotation(rads);
}

    }

    - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
[super touchesBegan:touches withEvent:event];
NSArray *allTouches = [touches allObjects]; 
CGPoint location = [[allTouches objectAtIndex:0] locationInView:self.view];

if(CGRectContainsPoint(grid1Btn.frame, location))
{
    selected = 1;
}
    }

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        selected = -1;
    }

2 个答案:

答案 0 :(得分:0)

急动是由触摸事件位置固有的不准确引起的。 位于足够靠近框架中心的触摸事件很可能偏向框架的对角相对象限,同时围绕框架的中心描绘圆形。 这会导致视频突然跳跃90度。 避免该问题的一种方法是在框架的中心附近引入死区。任何位于框架中心的给定半径内的触摸都不会触发重新计算的旋转。

希望这有帮助。

答案 1 :(得分:0)

您在计算中使用了一些frame.size.*。请注意,这些值(与bounds.size.*不同)受transform影响。请改用grid1.center。它也更合乎逻辑(你绕中心旋转)。

接下来你需要解决的是,当触摸开始时它不应该跳到新位置:)

相关问题