简体   繁体   中英

How do I rotate a UIView?

i finished this tutorial: http://dblog.com.au/iphone-development/iphone-sdk-tutorial-build-your-very-own-web-browser/

and now i want to add a function for rotating the window but I cant find a solution which helps me...

hope someone can help me here... I was searching for hours and found some codes, but they all wont work for me.. maybe I make something wrong... would be nice if someone can tell me where to place the code in which file (please look at the tutorial)

thank you very much

In this tutorial the tutor is using a web view in main window, so in app delegate we don't have shouldAutorotateToInterfaceOrientation function. What you have to do is create a new window base project and in the new project add new class of UIViewController type. In this new class add a web view from IB and in you app delegate import the new class, initialize it as

For example your new class name is FirstViewController then in app delegate.m

 #import "FirstViewController"

then in applicationDidFinishLaunching

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

then in your FirstViewController remove comment from method shouldAutorotateToInterfaceOrientation , because it is already there but just commented and also make sure that in shouldAutorotateToInterfaceOrientation function there is return YES; then you will be able to rotate a view.

Did you override the method shouldAutorotateToInterfaceOrientation ?

Example code for your controller:

// 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM