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 に答える