How to lock orientation of one view controller to landscape mode [iOS13] - uiviewcontroller

I have this solution: How to lock orientation of one view controller to portrait mode only in Swift
It was working fine but now on iOS 13 it didn't work anymore.
I try this solution: Screen rotation glitch on iPadOS 13
But it doesn't fix it.
Can someone have a working solution for iPhone app in portrait but only one UIViewController in landscape?
Edit:
I made a sample app, it is working fine with iOS 12.4.2 and iPhone 6.
But my problem it isn't working with iOS 13.1.3 and iPhone X.
=> we.tl/t-I3Um0U43fV
Edit 2:
Thanks to #donnywals, I success to keep my orientation as on iOS 12.
I just need some help to clean the main screen during transition. The "TOP" label is 90px from top of superview. As you can see, the current portrait page is resized during the transition.
Anyone know how to avoid it?

You can lock a view controller's orientation by overriding its supportedInterfaceOrientations property:
class ViewController: UIViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscape
}
// rest of your code
}
Edit:
Based on the sample project, you need to opt-out of the new presentation style to get the same behavior you had on iOS 13. Either set modalPresentationStyle = .fullScreen on the view controller that you're presenting in code or select the corresponding option in Interface Builder.

This is a tested code and I have implemented the same and its working for me - Forcing a controller to landscape mode
In the method viewWillAppear add the following:
NSNumber *value=[NSNumber numberWithInt: UIDeviceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
Add the following methods to the view controller
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
return (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight);}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);}
- (BOOL)shouldAutorotate {
return true;}

Related

Embedding UIViewController with intrinsicContentsize

I try to implement a view that has on the top a view with dynamic height and below a UICollectionView in a storyboard.
As long as I layout that directly in one ViewController everything works fine.
When the top view is managed by a separate ViewController and embedded, I always run into autolayout problems:
SizingSample[53440:11697282] [LayoutConstraints] Unable to simultaneously satisfy constraints. (
"<NSLayoutConstraint:0x6000030cc690 UILayoutGuide:0x600002af9180'UIViewSafeAreaLayoutGuide'.bottom == SizingSample.DynamicSizeView:0x7fda024197b0.bottom + 3 (active)>",
"<NSLayoutConstraint:0x6000030cc960 SizingSample.DynamicSizeView:0x7fda024197b0.top == UILayoutGuide:0x600002af9180'UIViewSafeAreaLayoutGuide'.top + 20 (active)>",
"<NSLayoutConstraint:0x6000030c52c0 'UIView-Encapsulated-Layout-Height' UIView:0x7fda024195d0.height == 0 (active)>",
"<NSLayoutConstraint:0x6000030cc870 'UIViewSafeAreaLayoutGuide-bottom' V:[UILayoutGuide:0x600002af9180'UIViewSafeAreaLayoutGuide']-(0)-| (active, names: '|':UIView:0x7fda024195d0 )>",
"<NSLayoutConstraint:0x6000030cc7d0 'UIViewSafeAreaLayoutGuide-top' V:|-(0)-[UILayoutGuide:0x600002af9180'UIViewSafeAreaLayoutGuide'] (active, names: '|':UIView:0x7fda024195d0 )>"
)
IMO the 'UIView-Encapsulated-Layout-Height' constraint breaks everything, but I haven't found any way to prevent it.
A striped down sample can be found at https://github.com/tengelmeier/viewcontroller-embedding-problem.git
How can I autolayout a view honoring the dynamic size of an embedded view(..controller)?
Because ios Automatically Apply Fixed Frame set while embedding ContainerController.you have to tell don’t translate autoresizing mask into LayoutConstraint.
You can do this by setting following Property in ContainerViewController(destination Controller) ViewdidLoad method.
view.translatesAutoresizingMaskIntoConstraints = false

iOS9: UIViewController: viewWillTransitionToSize is not called on split view changes when viewController is running in a second UIWindow

My application uses two UIWindows, a first running the main application and a second running some stuff to be shown in foreground of all. Both windows have a view controller. When the split view size of my application changes, viewWillTransitionToSize is called on the main applications UIViewController, but not on the viewController of the second window. When the orientation of the application changes, both methods are called. What can I do, that both viewWillTransitionToSize selectors are called?
As an workaround I'm observing the main application window size ...
[[UIApplication sharedApplication].delegate.window
addObserver:self
forKeyPath:#"frame"
options:0
context:0];
... and update the layout of the second window content:
-(void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if (object == [UIApplication sharedApplication].delegate.window) {
[self updateLayout];
}
}

Image ignores structure with foundation grid in mobile

This is my first question here so I apologize if it's not in the right formt. I don't know why but images work perfectly fine in my desktop computer but are out of place in my mobile devices. I used chrome's mobile simulator and it works fine there too. But not in the real mobile device.
Please help :(
There are many possibilities...
Without a look at your code, or knowing the OS for the device used it is impossible to provide a precise answer.
However, I experience similar issue with Foundation right out of the box... not sure why as well. In my application my up-loader re sizes each image and stores them in small, medium, and large folders. As a result, I need precise control on which image to load depending on device.
I came up with the system below which allows for the application of CSS to be applied according to device: This may or may not resolve you issue.
Mobile Detect
I went here to get Mobile Detect which I identifies the device used.
Code to call Mobile Detect
This calls the detect script and assigns device size to the variable: $thisImg
# mobile detect
require_once ($level.'core/ini/mobile-detect.php');
$detect = new Mobile_Detect; $deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
if($layoutType == 'mobile'){$thisImg = 'small';}
elseif($layoutType == 'tablet'){$thisImg = 'medium';}
elseif($layoutType == 'classic'){$thisImg = 'large';}
Store Device Size
To store the device size I use a hidden input with an id of img_sizer
echo '<input type="hidden" id="img_sizer" value="'.$this_img.'">';
jQuery
By assigning a class to the image you can now control the CSS on all the images with that assigned class according to device and can manage various image classes through jQuery.
$('img.respond').each(function(){
var which_size = $('#img_sizer').val(); // my hidden input
if(which_size == 'small'){$(this).addClass( "text-center" );} // add center class for small
})
Determining Folder Path
In my application I use the following jQuery to assign the proper folder path to the image source. The code came from Stack here
$('img.respond').each(function(){
var which_size = $('#img_sizer').val(); // my hidden input
var msrc=$(this).attr('src');
msrc=msrc.split('/'); //images, services, image.jpg
var lastelem = msrc.pop(); //images, services // lastelem: image.jpg
msrc.push(which_size); //images, services, large // lastelem: image.jpg
msrc.push(lastelem); //images, services, large, image.jpg
msrc=msrc.join('/'); //"images/services/large/image.jpg"
$(this).attr('src', msrc);
if(which_size == 'small'){$(this).addClass( "text-center" );} // add center class for small
})

Strange IE11 form fields bug after selecting from dropdown

I'm experiencing a major bug in IE 11 (latest version 11.0.9600.16521 on Windows 7). When on any form if I open a select dropdown all the other form fields on the page freeze. I can 'unfreeze' them by adjusting the Window size (causing a redraw). This seems to happen on any form what-so-ever.
To reproduce:
Open IE 11.0.9600.16521
Go to http://www.wikipedia.org/
Select any language from the language dropdown
Result:
language dropdown does not appear to get updated on the screen
the search box appears to be frozen - i.e. focus on select box and start typing but no text appears. However if you adjust the window size the form fields are updated and go back to working as normal (until you interact with another select element)
I can't find much in Google for this issue so maybe it's just something specific to my settings. Only thing that sounds somewhat similar to what I'm experiencing is this: http://connect.microsoft.com/IE/feedback/details/806679/ie-11-desktop-selecting-an-item-from-a-drop-down-list-on-a-webpage-causes-the-tab-to-crash. Anyone else able to reproduce this?
I had a similar issue with IE11 that turned out to be any modification to the .text property of an SELECT-option element. I eventually found the "hint" on stackoverflow here
How to fix IE select issue when dynamically changing options.
In my case I use straight JavaScript, and with so many inter-dependent SELECT boxes had to come up with a generic solution, so my solution was to intercept (defineGetter) assignment to any .text property of an HTMLOptionElement, and set a 1 ms timer to perform an add element and remove element as in the referenced post that is titled "I have the fix. We have to add and remove options list to trigger the rendering in IE8." Notice the reference to IE8, AFAIK IE has had several issues with SELECT boxes since at least IE7, possibly earlier.
So the code I added to one of my global scripts is as follows:
try { var IE11; // IE10 and IE11 removed ActiveXObject from the window object but it can still be instantiated
IE11 = new ActiveXObject('MSXML2.DOMDocument.6.0');
IE11 = null;
if (typeof(HTMLOptionElement) != "undefined") {
try { HTMLOptionElement.prototype.__defineSetter__(
'text',
function(original) {
return function(newValue) { var sel;
original.call(this, newValue);
if (!(sel=this.parentElement).fixIE) sel.fixIE = window.setTimeout(_fixIE_(sel), 1);
}
}(HTMLOptionElement.prototype.__lookupSetter__('text')));
} catch(e) {};
}
} catch(e) {}
}
// IE11 broke SELECT boxes again, modifying any options .text attribute "freezes" the SELECT so it appears disabled
function _fixIE_(selBox) {
return _fixIE_;
function _fixIE_(){ var lc = selBox.options.length;
selBox.options.add(new Option('',''));
selBox.options.remove(lc);
selBox.fixIE = undefined;
}
}
Phil
Go to programs
Then widdcom folder
Right click bttray
Go compatibility
Tick run as admin
Restart
I had the same problem in IE 11 on Dell Windows 7.
It was solved by turning off hardware rendering in IE, as you suggested in your link.

UIViewController interfaceOrientation problem

I have a Subclass of UIViewController as usual. When I load the App, I need to size some elements that I have to put in programmatically. Of course, the size depends on the interface orientation: So, I did:
- (void)viewDidLoad {
switch( [self interfaceOrientation] ) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
NSLog(#"Portrait");
break:
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
NSLog(#"Landscape");
break;
}
But no matter of the orientation of the simulator/device, the case is always Portrait in viewDidLoad/WillAppear, even if everything rotate correctly.
In the Plist I've added all supported orientations.
Hints?
Try [UIApplication sharedApplication].statusBarOrientation and check for UIDeviceOrientationPortrait, UIDeviceOrientationPortraitUpsideDown etc in your switch as [self interfaceOrientation] is unreliable in my experience.
1) Make sure that interface orientation in willAppear returns incorrect interface orientation.
2) try to look here http://developer.apple.com/library/ios/#qa/qa1688/_index.html
3) Make sure that main view controller is only viewcontroller in window (there is only one vc in window)
I was working with the rotations and orientations of the iOS App. I found that self.interfaceOrientation will always give you a correct result if called in viewDidAppear or after that.
[UIApplication sharedApplication].statusBarOrientation should be preferred when adding a view directly to UIWindow.
Hope it helps.