我正在尝试围绕它的当前位置旋转对象,
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;
答案 0 :(得分: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)];
}
答案 1 :(得分:1)
我通常会为翻译转换执行此操作:
sun_image.transform = CGAffineTransformMakeTranslation(dx,dy);
答案 2 :(得分: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
的{{1}}变量视为下方...
CGFloat