I've seen it on a previous app (forgetting the app name), where you could lock the current orientation of the screen.
Is there an easy way for this to be done, for example, simply using a button.
Just add an ivar to your app delegate that can be set by pressing the locking button. Then in all of your view controllers you can just check the ivar in the app delegate and respond to the
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
message according to your orientation ivar
Related
Hi I am new to iPhone development, I am developing a TabBar app it's contains 5 tabbar Items.
When I am close app at third TabBar viewController screen and again when I am opening app that time same third TabBar viewController screen only opening.
How to set App first screen as a default App opening Screen in iphone.
I need to set first screen as a default opening screen when ever open a app.
Could you please share your ideas here..
When you close the app, it doesn't KILL it, it just suspends it. Unless you set the option to kill it when you close it.
I suggest you read Apple Documentation For Application Flow
And possibly read the other documents Apple have provided for you there if you are new to all of this.
In your application's Info.plist, add a boolean key UIApplicationExitsOnSuspend with the value YES.
This will always exit the app (instead of running in background) when you close it. On opening app again, first view controller will appear instead of where you left it last time.
This is because you are setting your application to be run in background, so whenever you close your app the app will run in background and resume on startUp.
so just do one thing
Go to your info.plist and set value for
Application does not run in background to YES
If application is killed by default it loads all settings in Application Delegate method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Here you can modify your root view controller, which I presume is some kind of tab bar view controller.
So there is probably some code in that method which defines which tab to load.
However if you want to show specific tab after application enters in the foreground use Application delegate method:
- (void)applicationWillEnterForeground:(UIApplication *)application
Or
- (void)applicationDidBecomeActive:(UIApplication *)application
When exiting the app by for example pressing the home button on the iPhone the app is not terminated. Instead the execution is suspended but the app will remain in memory until iOS decides to remove it. This means that when you enter the app again it will be in the same state you left it. You can see if the app is still in memory by doubletapping the home button.
When your app becomes active the method applicationDidBecomeActive: in your UIApplicationDelegate will be called. You can implement that method to set the state you want your app to be in when it is restored.
I would not recommend explicitly killing the app when it is suspended. That forces the app to be reloaded each time it is started which will degrade performance.
For more information see Apple's documentation on app states.
i developing an iPad app in which i working with images.The application is worked fine in portrait mode when application launched in portrait mode but it gives me ridiculous problem with frames when app i launched in landscape mode. My all functionality already written in "shouldAutorotateToInterfaceOrientation" this method. If i able call this method then it will remove all problem of frames.How i call shouldAutorotateToInterfaceOrientation method in my application in any function?
You don't call shouldAutorotateToInterfaceOrientation: yourself. UIKit sends this message to your view controller in order to know if the view controller should be rotated or not. Move your layout code from shouldAutorotateToInterfaceOrientation: to willRotateToInterfaceOrientation: and it should work.
Check out the UIViewController Class Reference.
shouldAutorotateToInterfaceOrientation:
Your implementation of this method should simply return YES or NO based on the value in the interfaceOrientation parameter. Do not attempt to get the value of the interfaceOrientation property or check the orientation value reported by the UIDevice class. Your view controller is either capable of supporting a given orientation or it is not.
I've built an app that uses a UITableView inside a UINavigationController, inside a UITabBarController. Every entry in the UITableView opens up a view that contains some basic text, buttons, but most importantly, an MPMoviePlayerController that plays audio when started. A user can click this MPMoviePlayerController and continue to browse around the rest of the app (different tabs, or moving back in the navcontroller, opening other views from the tableview) and continue to hear the audio.
I'd like the user to be able to return to the view with the active MPMoviePlayerController at any time. I understand how I would go about allowing the user to return to a certain view from any view, but I'm struggling with how to prevent that view from being reloaded when the user tries accessing the same view.
Is there any way I can save a view in memory? Or save the active MPMoviePlayerController as some type of global object, so that I can at least access that from anywhere?
I appreciate any and all help. Thanks!
I'd recommend you create a property for the MPMoviePlayerController in your app's UIApplicationDelegate (which you can then access from anywhere in the code with [UIApplication sharedApplication].delegate but you will need to cast to your UIApplicationDelegate subclass).
When you come to enter the screen which plays content, check whether your movie player property in the app delegate is nil, if it is create it, otherwise re-use it.
Don't forget to release the reference to your MPMoviePlayerController when the media stops playing, or when the media has already stopped and you get a memory warning or when your app shuts down.
The down side of this approach is it causes coupling between most of your view controllers and your app delegate. You could mitigate this with the use of a protocol however.
You should simply retain it. Like this [myView retain] and keep a pointer to it in where you need. When you want myView to appear, just add it as a subview to current visible view like[myController.view addSubview:myView].
Hope that will help, Good luck!
I've found that even adding a retain doesn't do the trick. I've actually found the best success with overriding the setView (since part of unloading the view involves calling setView:nil. I have a BOOL that gets set the FIRST time the VC loads and once thats set it will never allow setView to be called again.
- (void) setView: (UIView*) view{
NSLog(#"MainViewController: setView");
// this is our attempt to stop iOS from unloading our view.. when iOS tries to unload your view they call setView:nil.. so, no!
if(!viewDidAppear) [super setView:view];
}
A little bit of a hack, but you can override setView: in your subclass so that it never allows to set the view to nil:
-(void)setView:(UIView *)view
{
if (view == nil) return;
[super setView:view];
}
I know the app delegate can say "yo man, I want thais new landscape orientation!" or "no thanks, don't want landscape!" and then the device won't do it.
How to implement this?
The active view controller's shouldAutorotateToInterfaceOrientation: method determines whether the interface will rotate.
For launch, there is a key in your Info.plist file that needs to be set if you want to be able to launch in orientations other than portrait.
I prefer to get the orientation notification by registering UIDeviceDidChangeOrientationNotification. The delegate of UIViewController about orientation always confuses me. I prefer to control the animation effect by myself.
When the user changes NsuserDefaults in settings on the iPhone and activates my app after it being suspended, i want to reload the active view.
How can i do this?
You could implement the applicationDidBecomeActive: method in your application delegate, or register for the UIApplicationDidBecomeActiveNotification notification in any other object.
- (void)applicationWillEnterForeground:(UIApplication*)application on the App Delegate is invoked when coming out of suspend.
Implement this method, in it check if the setting you are about has changed, find your topmost view controller and reload it's view then.