UIActionSheet not rotating in landscape mode? - objective-c

I have a UIActionSheet and I set it's view like this:
[popup showInView:[[UIApplication sharedApplication] keyWindow]];
this works fine in portrait mode, but when I switch to landscape, it stays portrait. What am I doing wrong?
Thanks.

You're showing it in the window (which is not rotated), rather than in a view controller's view (which is). Pass the main view of your currently-visible view controller instead, or use showFromTabBar: or showFromToolbar: on iPhone or showFromBarButtonItem:animated: or showFromRect:inView:animated: on iPad.

You can use this instead:
[popup showInView:[UIApplication sharedApplication].keyWindow.rootViewController.view];

[popup showFromToolbar:self.view];
Special for ActionSheet within ActionSheet.

Related

FullScreen Loading View didn't work

I have been working on a fullscreen loading view for my apps, but it can't block any user interaction. The way I implement it is like this:
Create a singleton object - LoadingView
Call [LoadingView show] - add the loading view to [[[UIApplication sharedApplication] delegate] window]
So I want to ask :
Is my concept wrong?
Are there any method calls that can disable all user interaction to my apps?
Is there another better way to do this? (I prefer knowing about the principle inside than just using others' libraries)
Thanks
I use such way to block user interaction:
create UIView with window frame
set view's user interaction enabled to true
(optional) add UIActivityIndicator to view
add view to window subviews
when I need to show it I set hidden to NO and use bringSubviewToFront function to show loading view
when I don't need it I set hidden to YES and use sendSubviewToBack
id application = [[UIApplication sharedApplication] delegate];
UIView *loadingView = [[UIView alloc] initWithFrame:[[application window] frame]];
loadingView.userInteractionEnabled = YES;
loadingView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
[[application window] addSubview:loadingView];
Are you wanting to create a splash screen when the application starts? If so, all you need to do is add an image file called Default.png and/or Default#2x.png (for retina displays) to your project. This image will work as a splash screen for when the app launches.
You can also control the splash screen info.plist file.
Read more about the iOS launch screen here.

presentModalViewController gives a black screen

In an alert view method I implemented the following (pretty standard) piece of code for popping a modal view:
else if (buttonIndex == 1) {
EmergencyPlanViewController *emergencyPlanView = [[[EmergencyPlanViewController alloc] init] autorelease];
[emergencyPlanView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:emergencyPlanView animated:YES];
}
Somehow it gives me a black screen as result. I can't find what is wrong here.
I created the window in my MainStoryBoard and customized the class of the viewcontroller in IB to EmergencyPlanViewController.
The viewDidLoad method of the emergencyPlanView is triggered but it looks like the view is not loaded. Anyone an idea what's wrong here?
EDIT:
To be clear, I am not using seperate xib-files in my project. I only use the storyboard
In the xib file, is your UIView set to the File Owner's view. That is probably the problem. Also if you just apply init, that will load the EmergencyPlanViewControllerinterface builder file with the same name:
EmergencyPlanViewController.xib
So make sure in that case that either:
The EmergencyPlanViewController nib is indeed: EmergencyPlanViewController.xib
or that you write instead of init: initWithNibName://whatever nib name here
I managed to fix the black screen issue when presenting a modal view controller by setting a background color to the view in Interface Builder. I noticed that by default the background color of the view is set to something like black/white (see picture attached), although it appears in white. I don't know exactly what does this mean or how it is responsible for showing a black screen, but setting a single color or texture fixed it. PS: I've faced this when migrating from iOS SDK 5 to 6.
ios6
Try this:-
EmergencyPlanViewController *emergencyPlanView=[[EmergencyPlanViewController alloc] initWithNibName:#"EmergencyPlanViewController" bundle:nil];
emergencyPlanView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:emergencyPlanView animated:YES];

iPad Orientation issues when switching between two views and from portrait to landscape vice versa

I am building a simple app with two View Controllers, I am testing the code using the iPhone Simulator, everything seem to be working fine. The problem happens when I rotate from Portrait to Landscape or from Landscape to portrait. This is the logic of the app, the app always launched in Portrait, I have a button to on the first View to Switch from View1 to View2. On View2 I have another button to switch from View2 back to View1. Let say, I am in Portrait mode, I switch from View1 to View2, then rotate the iPad (in the simulator) from Portrait to Landscape, when I switch back from View2, i.e to go back to View1. View1 screen/view is displayed in Portrait with View2 screen displayed in the background, ie part of View2 is displayed in the background, I guess because View1 was originally in Portrait mode.
The question is.. Has anyone had this issue before, if so, any code to fix this issue, secondly, how can I identify in the code which orientation the device is and which orientation the view is in.
This method is to switch to View 2:
-(IBAction) switchToView2: (id) sender {
SecondViewController *myViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.view addSubview: myViewController.view];
[UIView commitAnimations];
}
This method is to switch back to View1:
-(IBAction) switchBackToView1:(id) sender {
[self.view removeFromSuperview];
[UIView commitAnimations];
}
From your code:
[self.view addSubview: myViewController.view];
It makes me believe that your 2 views is a subview of myViewController.view. which explains why they're both showing at the same time. it would make sense to have seperate view controllers for different views.
First i think
[UIView commitAnimations];
is not necessary :
From Apple
commitAnimations
Marks the end of a begin/commit animation block and schedules the animations for execution.
second in Interface Builder have you set the property of your controller to landscape ?
Hope this Help (sorry for my bad English)
Yes, that would happen if you dont put any orientation change handling in your code. Check out this guide on how you can set your view to automatically or manually handle adjustment on orientation change.
Or if you do have handling already, then it may be because of how you are adding/removing your views. For better handling, I think you should try the UINavigationController way of managing views. i.e., instead of addSubview: and removeFromSuperview:, you should use pushViewController:animated: and popViewController:animated: instead.
And yes, as Yoos said, [UIView commitAnimations] is not needed in your code above.
Hope this helps.

positioning problem with uisplitviewcontroller in left view

i got a little problem, when launching my splitview in landscape, there is a little black space above my left view controller:
after rotating my ipad to portrait and switching back to landscape, the space is gone.
if i load the uitableviewcontroller directly into the left view, and not in a navigationcontroller, it works fine:
any ideas why this is happening ??
// Produkte
self.produkteMainTableVC = [[produkteMainTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *produkteMainNavigationController = [[UINavigationController alloc] initWithRootViewController:self.produkteMainTableVC];
self.produkteDetailVC = [[produkteDetailViewController alloc] initWithNibName:#"produkteDetailViewController" bundle:nil];
self.produkteSplitVC = [[UISplitViewController alloc] init];
self.produkteSplitVC.delegate = self.produkteDetailVC;
self.produkteMainTableVC.produkteDetailVC = produkteDetailVC;
[self.produkteSplitVC setViewControllers:[NSArray arrayWithObjects:produkteMainNavigationController,self.produkteDetailVC,nil]];
thanks for all help!
edit:
its exactly 20px like the statusbar. does that help anyone?
edit2:
doing something like this:
if(self.navigationController.navigationBar.frame.origin.y >= 20.0) {
self.navigationController.navigationBar.frame = CGRectMake(self.navigationController.navigationBar.frame.origin.x, 0.0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);
}
results that:
a little improvement i would say. but i have no idea how to stick my tableview underneath the navigationbar.
I know this is a very old topic but maybe it'll help other people...
I had the same issue (with the same configuration : splitview in tabbar).
This property solved it !
[self.splitViewController setWantsFullScreenLayout:YES];
UINavigationController has a nasty habit of shifting its contents down by 20px, depending where you place it. I'm guessing it's doing it here because your split view controller is inside of a tabbar controller, and Apple has not blessed this type of arrangement.
I've run into this same issue, with out a resolution. The only thing I've noticed is this does NOT happen when the master does not include a UINavigationController as its root.
Anyone figure a solution to this?
Here's what I did, and it seems to work fine.
I created my own custom tab-view controller, derived from UIViewController. In viewDidLoad I add a UITabBar to the bottom of the view and set the delegate to myself so I can handle tab changes. (I return this UITabBar as the rotatingFooterView) Tab changes result in swapping the current view controller, just like a real UITabBarController. When swapping view controllers (sometimes a UISplitViewController, hosting a UINavigationController in the master view), I add and position the view-controller's view within my view, above the UITabBar. I'm also careful to forward viewWill/DidAppear/Disappear calls to the current view controller, as well as each of the will/didRotate messages.
seems that this problem occurs from iOS 7.0. Setting the frame of UINavigationBar in some cases doesn't work. I think this can solve your problem :
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
self.navigationController.view.frame = CGRectMake(0, -20, self.navigationController.view.frame.size.width,
self.navigationController.view.frame.size.height);
}
This code should be called only once (for example in - (void)viewDidLoad ).
In my case it works for all device orientation.

UIModalPresentationFormSheet on iPad in landscape mode

I created a UIViewController view from XIB with modalPresentationStyle set to UIModalPresentationFormSheet and everything works great in portrait mode. When I switch to landscape the view gets moved upperleft (it's not centered as it should be) and most part of it is clipped.
Any ideas why this is happening and how to solve it?
Thanks
I had this problem as well. Turned out, I had the autorotate function set to Portrait for both the modal controller and the calling controller.
In iOS 7, to solve the problem of the modal view controller to appear to the left after apparition of the keyboard (problem that I have when I present an EKEventEditViewController in UIModalPresentationFormSheet, I do :
[self presentViewController:modalViewController animated:YES completion:^{
modalViewController.view.superview.center = self.view.center;
}];