tags:

views:

274

answers:

2

I am working on an application which needs to rotate the slider at one end. However, by using CGAffineTransformMakeRotation(), I can only rotate the slider at the centre.

What should I do in order to rotate the slider at the end point? If possible, please give a short paragraph of sample code. Thanks a lot.

+3  A: 

I rotate a UIImageView by setting the anchorPoint property for the view's layer. e.g.

myView.layer.anchorPoint = CGPointMake(0.5, 1.0);

and then applying a CATransform3DRotate as the layer's transform property

CATransform3D rotationTransform = CATransform3DIdentity;
rotationTransform = CATransform3DRotate(rotationTransform, positionInRadians, 0.0, 0.0, 1.0);
myView.layer.transform = rotationTransform;

I found this from Apple's metronome example, so it's worth checking that out. Hope that helps

cidered
Thank you very much. I have succeeded in transforming the slider.
dobby987
+1  A: 

I second cidered's answer. To do what you want using CGAffineTransforms, you have to compose transformations until you get the effect you're looking for:

CGAffineTransform transform = CGAffineTransformMakeRotation(1.0);
transform = CGAffineTransformTranslate(transform, slider.frame.size.width / 2, 0.0);
slider.transform = transform;
Adrian Kosmaczewski
Thank you very much.
dobby987