开发者

Question about rotating a slider

开发者 https://www.devze.com 2022-12-15 21:32 出处:网络
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.

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.


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


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消