0

我正在旋转一个轮子,其中包含各种子视图(UIImageViews 和 UIButtons)但是当我要求它显示每个子视图的每个中心时,它每次都给我相同的值。

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {   
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSSet *allTouches = [event allTouches];

    int len = [allTouches count]-1;

    UITouch *touch =[[allTouches allObjects] objectAtIndex:len];
    CGPoint location = [touch locationInView:[self superview]];
    float theAngle = atan2( location.y-self.center.y, location.x-self.center.x );

    totalRadians = theAngle;

    [self rotateImage:theAngle];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}

-(void) rotateImage:(float)angleRadians{

    self.transform = CGAffineTransformMakeRotation(angleRadians);
    CATransform3D rotatedTransform = self.layer.transform;
    self.layer.transform = rotatedTransform;    
    int count = 0;
    for (UIView *subview in self.subviews)
    {
    count++;    
        //these values are always the same
    NSLog(@"%i %f %f", count, subview.center.x, subview.center.y);
    }
}

有人可以告诉我为什么即使在旋转并放置在不同的位置之后,这些值总是相同的?

谢谢!

4

1 回答 1

1

为了摆脱评论中所说的内容,中心在超级视图范围内表示。边界不受旋转影响,{0,0} 始终位于视图的左上角。

为了得到你想要的,你需要将旋转应用到中心点,

rotatedCenter = CGPointApplyAffineTransform(subview.center, self.transform);

于 2010-10-26T10:59:45.713 回答