AllVisible splitView on iPhone iOS 8 - ios

A heard that is possible to show split view on iPhone in landscape mode on iOS 8? Is it true?
I tried:
let splitViewController = self.window!.rootViewController as UISplitViewController
splitViewController.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible
splitViewController.preferredPrimaryColumnWidthFraction = 0.3
Everythings works great but only on iPad. On iPhone I have still full width masterView.

Related

I want to run a particular viewcontroller in regular height trait environment in iOS Swift

I have many View Controllers in my ios App and they all support rotation but for one of my scenes (and only one), I would like to detect the trait environment and run it only if the device trait environment is regular height (so an iPhone in portrait or an iPad in both portrait or landscape). How to achieve this?
So I want to get the vertical size class and based on which I want to freeze the orientation. So if verticalSizeClass == .compact, the orientation of views of the UIViewController should be portrait else the orientation of the views of the UIViewController can be the same as that of the screen.
I am using the following code
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
let tc = UIScreen.main.traitCollection
let orientation: UIInterfaceOrientation = UIApplication.shared.statusBarOrientation
if tc.verticalSizeClass == .compact {
return .portrait
} else {
return orientation
}
}
But it's giving error messages for autolayout. I am using Xcode 10.2, running Swift 5.0.
There is a question How to force view controller orientation in iOS 8?
but it is from objective c perspective and more importantly I want the viewController to rotate as per the device, while the question "How to force view controller orientation in iOS 8?" locks the orientation to portrait or landscape and does not care about landscape left or right.
You have correctly used the size class to detect the trait environment. But try overriding this stored property of UIViewController instead.
override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
get{
if .compact == UIScreen.main.traitCollection.verticalSizeClass{
return .portrait
}
return .all
}
}
When the user changes the device orientation, the system calls this
method on the root view controller or the topmost presented view
controller that fills the window. If the view controller supports the
new orientation, the window and view controller are rotated to the new
orientation. This method is only called if the view controller's
shouldAutorotate method returns true.
Reference Documentation
as I understand you want to get the height of specific Scene
let screenSize: CGRect = UIScreen.main.bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height
print("Screen width = \(screenWidth), screen height = \(screenHeight)")
this gives you the height and the width.

Crash on presenting UIImageViewController at iPad in Landscape mode

I have an iPad app that should works only at Landscape mode.
But I have to show UIImagePickerController.
According to documentation UIImageController works only with Portrait mode.
If I disabple Portrait orientation and present UIImageViewController I receive crash with
"Supported orientations has no common orientation with the
application, and [PUUIAlbumListViewController shouldAutorotate]”
How I can configure project to disable Portrait mode at iPad and allow to show UIImagePickerController?
My solution without setting Portrait mode
let imagePicker = UIImagePickerController()
imagePicker.modalPresentationStyle = .popover
imagePicker.popoverPresentationController?.sourceView = self.view
imagePicker.sourceType = (UIImagePickerController.isSourceTypeAvailable(.camera)) ? .camera : .photoLibrary
imagePicker.delegate = self
You have no choice. As you have already said, the solution is to enable portrait orientation in your app.
If the intersection between what the view controller requires and what the app permits is null, the app will crash (as you have seen).

Can I use separate storyboards for iPhone and iPad(Portrait and Landscape)?

I am working on an app which supports iPhone and iPad.
For iPad we are supporting both portrait and landscape (iOS 9.0). But for some reason, to satisfy the requirement we have to maintain separate storyboards for landscape UI. Is this accepeted by Apple.
Want to make sure that this is as per APPLE guidelines.
If you want different storyboard you can try the following code in the main view controller:
Obj-C
- (void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
NSString* storyboard = (size.width > size.height ) ? #"lanscape" : #"portrait";
UIStoryboard* mainView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
UIViewController* viewcontroller = [mainView instantiateInitialViewController]
// remove privious view controller
// add newViewcontroller
}
Swift
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
let storyboardName = (size.width > size.height ) ? "lanscape" : "portrait"
var mainView: UIStoryboard!
mainView = UIStoryboard(name: storyboardName, bundle: nil)
if let newViewcontroller : UIViewController = mainView.instantiateInitialViewController() {
// remove privious view controller
// add newViewcontroller
}
}
I hope it could help you.
You can use two separate story boards for iPhone and iPad only if there's 2 orientations(Landscape and portrait) needed for iPad and the UI for each orientation changes drastically. Since iPad's size class is Regular-Regular for both orientations you can still go ahead and build UI in one storyboard.
There can be situations where you cannot keep manipulating constraints or views for different orientations under same size class. It would become cumbersome and too complicated further.
Hence its always a better idea to keep 2 storyboard (1 for another orientation of iPad) them separate if the UI for both orientation for iPad is different.
However for iPhone and for one of the orientaion of iPad you can still go ahead with 1 storyboard as they inherit different size classes.

UINavigationController ios7 - NavTab in front of view

I'm developing a new application to ios and i'm using UINavigationController. When i'm developing in the Xcode the view is that:
But in the simulator (iOS 7) this is the result:
And when i use iOS 6 in the simulator, this is the result:
This is my code for use UINavigationController:
RootController *controller = [[RootController alloc]init];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:controller];
self.window.rootViewController = navController;
As already pointed out, a straightforward solution is adding this snippet in your viewController's viewDidLoad:
if ([self respondsToSelector:#selector(setEdgesForExtendedLayout:)]) { // if iOS 7
self.edgesForExtendedLayout = UIRectEdgeNone; //layout adjustements
}
You need to set Delta of your view controller.
Switch Story board to ios6.1 or later from utility area (1st item).
Then select view of your Vc and in size inspector menu in utility area there will be delta section below frame.
There will be triangle before every delta.
Triangle y to 64 (you should be on ios6.1 or later of your storyboard).
If you need help on Deltas visit : Interface Builder: What are the UIView's Layout iOS 6/7 Deltas for?

Retina 3.5 has wrong origin after rotation in modal view to UIInterfaceOrientationLandscapeLeft

I have a weird behaviour with my view representation.
my structure:
Window -> MyTabbarController -> GraphViewController -> (modal) SelectItemViewController;
settings of Window:
After I updated my app to the retina 4 resolution (and set the UIWindow size in the Window.xib to Retina 4 fullscreen), the origin of myTabbarController was set to 0,88 in the Retina 3.5 devices (in retina 4 there are no problems).
If I use non-modal controllers, I can rotate till end of days, everything works fine.
But if I call the modal view in UIInterfaceOrientationLandscapeLeft (for UIInterfaceOrientationLandscapeRight works everything fine) or dismiss the modalView in same state, the parentView of GraphViewController (MyTabbarController) gets a wrong frame...
CALL the modal view:
DISMISS the modal view
I am thankfull for every help.
ps: setting the UIWindow size to Retina 3.5 fullscreen or freeform makes it looking wrong in iPhone 5. Also setting the modalPresentationStyle doesn't do anything :/
Problem was solved by setting the window size in code:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
window.frame = [UIScreen mainScreen].bounds;
window.rootViewController = tabBarController;
...
after setting this, the frame was always set on the correct position.
I think it was just a problem of the binding of the view to the window and it's orientation in this "container" (screen has a 'width' of 480 but frame 568 pixel in landscape mode. And the gray part was just this difference (88 pixel) to the right (non-bounded) side of the modal view)

Resources