-1

我正在尝试围绕它的当前位置旋转一个对象,

CGAffineTransform trans =   CGAffineTransformMakeRotation(compass_heading );
trans = CGAffineTransformTranslate(trans, 0, 90);
sun_image.transform = trans;

但它没有效果,sun_image不动!但是如果我把它改成这个并在 X 轴上平移它就会移动!这是什么意思?

CGAffineTransform trans =   CGAffineTransformMakeRotation(compass_heading );
trans = CGAffineTransformTranslate(trans, 90, 0);
sun_image.transform = trans;
4

3 回答 3

2

以下是旋转对象的方法:

    CGFloat rotation = M_PI_2;

    CGAffineTransform currentTransform = sun_image.transform;
    CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);

    [sun_image setTransform:newTransform];

有了CGAffineTransformTranslate你可以移动一个对象,所以你必须使用CGAffineTransformRotate.

对于位置经理:

-(void) locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{     
     //set the anchorPoint as the lower right corner of the layer
     sun_image.layer.anchorPoint = CGPointMake(1, 1);

     [sun_image.layer setAffineTransform:CGAffineTransformMakeRotation(-1*newHeading.trueHeading*3.14159/180)];
}
于 2013-07-17T10:58:52.517 回答
1

我通常为翻译转换这样做:

sun_image.transform = CGAffineTransformMakeTranslation(dx,dy);
于 2013-07-17T11:08:17.413 回答
1

首先UIImageView使用您的视图中心属性设置您的中心,如下所示..

yourImageView.center = self.view.center;

GestureRecognizer如下设置后..

    UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
    [rotationRecognizer setDelegate:self];
    [yourImageView addGestureRecognizer:rotationRecognizer];
    [rotationRecognizer release];

然后使用这种波纹管方法进行旋转UIImageView

-(void)rotate:(id)sender 
{
    UIView *imgTempGest = [sender view];

    if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) 
    {
        lastRotation = 0.0;
        return;
    }
    CGFloat rotation = 0.0 - (lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);

    CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
    CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);

    [[(UIRotationGestureRecognizer*)sender view] setTransform:newTransform];

    [imgTempGest setTransform:newTransform];

    lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
}

像下面这样lastRotation的变量CGFloat..

CGFloat lastRotation;
于 2013-07-17T11:11:55.663 回答