在Cocoa Touch中旋转UIView

PF1*_*PF1 19 iphone cocoa-touch rotation uiview

我见过其他有过这个问题的人,但是大部分的回复都不适用于最新的3.0版iPhone OS.无论如何,我想知道如何在没有来自加速度计的任何输入的情况下以编程方式旋转UIView.到目前为止我找到的代码:

CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
view.transform = transform;
CGRect contentRect = CGRectMake(-80, 80, 480, 320);
view.bounds = contentRect;
Run Code Online (Sandbox Code Playgroud)

但是,这对UIView不起作用(在我的测试中).有什么东西我必须做我的AppDelegate才能使这个/其他代码运行,或者有更好的方法来做同样的事情吗?

谢谢你的帮助!

ash*_*ish 40

这对我有用

 CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI_2);
 self.view.transform = transform;

 // Repositions and resizes the view.
 CGRect contentRect = CGRectMake(0,0, 480, 320);
 self.view.bounds = contentRect;
Run Code Online (Sandbox Code Playgroud)

  • 并使用M_PI_2而不是M_PI/2 (32认同)
  • 使用M_PI而不是3.14159 (14认同)