开发者

iOS Align a UIView parallel to X-Z plane

I realize that by default a UIView is parallel to the X-Y plane, the Z-axis coming straight at you.

How do I rotate this UIView so that it is parallel to X-Z plane? I think I have to use CATransform3D but am not sure what angle I should give it? M_PI_2 or -M_PI_2 ?

Anybody has any idea? Thanks for help...

EDI开发者_如何转开发T: I know that by doing this, the UIView will not be visible to the user, but I want to set a particular UIView this way & then do some rotation animation on it. So this is what I want..


WHat you probably want to do is to apply a transformation to the view's backing layer. The transform property on UIView is an affine transformation, not allowing any 3D manipulation. But accessing view.layer.transform you have a full 4x4 matrix for your transformation needs, allowing nice funky 3d stuff.

  1. Add QuartzCore.framework to your target.
  2. Import <QuartzCore/QuartzCore.h> to get access to the CALayer API.
  3. Code away.

For example:

// Rotate 1/4 by the Y-axis.
myView.layer.transform = CATransform3DMakeRotation(M_PI_2, 0.0f, 1.0f, 0.0f);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜