如何旋转UIView?

时间:2011-04-26 12:41:14

标签: iphone objective-c ios

我完成了本教程: http://dblog.com.au/iphone-development/iphone-sdk-tutorial-build-your-very-own-web-browser/

现在我想添加一个旋转窗口的功能,但我找不到能帮助我的解决方案......

希望有人能在这里帮助我...我正在寻找几个小时并找到了一些代码,但他们都不会为我工作..也许我做错了...如果有人可以告诉我在哪里安排会很好文件中的代码(请查看教程)

非常感谢

2 个答案:

答案 0 :(得分:1)

在本教程中,导师在主窗口中使用Web视图,因此在app delegate中我们没有shouldAutorotateToInterfaceOrientation功能。你要做的是创建一个新的窗口基础项目,并在新项目中添加新的UIViewController类类。在这个新类中添加一个来自IB的Web视图,在你的app delegate中导入新类,将其初始化为

例如,你的新类名是FirstViewController然后在app delegate.m

 #import "FirstViewController"

然后在applicationDidFinishLaunching

FirstViewController *fvc = [[FirstViewController alloc] init];
[window addSubView:fvc.view];

然后在你的FirstViewController中删除方法shouldAutorotateToInterfaceOrientation中的评论,因为它已经存在但只是评论并确保在shouldAutorotateToInterfaceOrientation函数中有return YES;然后你就能够旋转视图。

答案 1 :(得分:0)

您是否覆盖了方法shouldAutorotateToInterfaceOrientation

控制器的示例代码:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    // return (interfaceOrientation == UIInterfaceOrientationPortrait);
    retrun YES; // to support all rotation
}