在 Cocoa Touch 中旋转 UIView
我见过其他人也提出过这个问题,但大多数回答都不适用于最新的 3.0 版 iPhone 操作系统。不管怎样,我想知道如何在没有来自加速度计的任何输入的情况下以编程方式旋转 UIView。到目前为止我找到的代码:
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
view.transform = transform;
CGRect contentRect = CGRectMake(-80, 80, 480, 320);
view.bounds = contentRect;
但是,这不适用于 UIView (在我的测试中)。我是否必须对 AppDelegate 执行某些操作才能使此/其他代码正常运行,或者是否有更好的方法来执行相同的操作?
感谢您的帮助!
I have seen other people who have had this question, but most of the responses aren't working on the latest 3.0 build of iPhone OS. Anyway, I'm wondering how I can programatically rotate a UIView without any input from the accelerometer. The code I have found so far:
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
view.transform = transform;
CGRect contentRect = CGRectMake(-80, 80, 480, 320);
view.bounds = contentRect;
However, this doesn't work for UIView (in my testing). Is there something I have to do my AppDelegate in order for this/other code to function, or is there a better way of doing the same thing?
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用
this works for me
我在这方面取得了成功:
I had success with that:
不确定这是否被认为是私有API,所以你可能不想使用它,但如果你想在不倾斜设备的情况下强制改变方向,你可以尝试调用:
我没有测试它仍然可以在3.1.2上工作。虽然我知道它可以在 3.0 上运行。
Not sure if this is considered private API, so you may not want to use it, but if you want to force the orientation to change without tilting the device, you can try calling:
I have not tested that it still works on 3.1.2. though I know it works on 3.0.