i want to set my application in Portrait mode as default . so how to implement it ?
all screen of the application set default as Portrait mode ..
Check this BlackBerry UI guide:
Specifying the orientation and direction of the screen
This set default portrait mode:
public void disableOrientationChange()
{
int directions = Display.DIRECTION_NORTH;
UiEngineInstance engineInstance = Ui.getUiEngineInstance();
if (engineInstance != null)
{
engineInstance.setAcceptableDirections(directions);
}
}
Related
I need to make a different layout for iPad on landscape and portrait orientations, but size classes on iPad are always regular/regular. Recommended way to adapt interfaces by Apple is to use adaptive layout with size classes, but on iPad there is no difference between portrait and landscape mode.
Is there any way to present different layout on portrait and landscape orientation on iPad without detection device orientation?
As a example, on iPhone (compact/regular) will be shown as:
And on iPad, in landscape (regular/regular) will be shown as:
So, the goal is show the iPhone layout on iPad when is in portrait mode.
Thanks!
You can force apply horizontal size class depending on orientation. If I correctly understood your goal here is a demo of possible approach (tested with Xcode 12.1 / iOS 14.1):
struct DemoViewSizes: View {
#Environment(\.horizontalSizeClass) var horizontalSizeClass
#State private var orientation = UIDevice.current.orientation
var body: some View {
Text("root_view_here")
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
orientation = UIDevice.current.orientation
}
.environment(\.horizontalSizeClass, orientation == .portrait ? .compact : .regular)
}
}
I am adapting a React Native app from iPhone to iPad and I am facing a weird problem. I suspect of a bug with RN.
When user is in landscape mode and launches the app, it will have a Splash Screen in landscape mode, and there is no problem with that. But the app keeps recognizing Dimensions.get('window').width as the width of landscape mode width even after I lock screen to portrait.
My app structure goes like this. The mother component of the app has a code that lock the app in portrait mode, like this:
var Orientation = require('react-native').NativeModules.Orientation;
componentWillMount(){
Orientation.lockToPortrait();
}
From that initial component other components are loaded via a router react-native-router-flux. Inside those component UI components were styled using React Native Dimensions API. like this:
<View style={{ width: Dimensions.get('window').width - 10}} />
It works perfectly on iPhones, because iPhones are always on Portrait mode during app launch. But on iPads, when the user has his screen on landscape mode (during app launch), the entire app looks weird because RN is reconizing the screen height as the screen width. When the user launches the app while in portrait mode, the same problem won't happen. It should not be happening since the Dimensions.get('window').width are being called just after the app is already locked to portrait. It makes no sense to me...
Unhappily I really need to be able to have landscape mode too, since inside some screens I force the user to be on landscape mode, by doing Orientation.lockToLandscape()
Any solutions to this problem?
I have come up with a hack in order to get my app working quickly, but I don't think this is the best method. I basically measure the screen to know in which orientation my app got locked. Like this:
const getWidth = (percentage: number) => {
if (Dimensions.get('window').width > Dimensions.get('window').height) {
return (Dimensions.get('window').height * percentage) / 100;
}
return (Dimensions.get('window').width * percentage) / 100;
};
const getHeight = (percentage: number) => {
if (Dimensions.get('window').width > Dimensions.get('window').height) {
return (Dimensions.get('window').width * percentage) / 100;
}
return (Dimensions.get('window').height * percentage) / 100;
};
After that I can create Stylesheet.create() objects that adapt to the screen orientation. Like this:
StyleSheet.create({
fullWidth: {
width: getWidth(100) - 60,
}
})
instead of:
StyleSheet.create({
fullWidth: {
width: Dimensions.get('window').width - 60,
}
})
I used this workaround based on pedrosimao answer:
Dimensions.addEventListener('change', e => {
const{width,height}=(e.window)
const getHeight = (percentage) => {
if (width > height) {
this.setState({orientation:'landscape'})
return ((height * percentage) / 100)
}else{
this.setState({orientation:'portrait'})
}
return height
}
this.setState({width:width,height:height,height2:getHeight(50)})
});
of course this don't works if you don't change the orientation at least once.
You must use some initial state like this:
this.state={
height2: (Dimensions.get('window').height>Dimensions.get('window').width) ? Dimensions.get('window').height :(Dimensions.get('window').height*50)/100 ,
}
I have web page defined in the core library as view to fill whole screen:
Content = new WebView
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Source = "https://google.com",
};
Unfortunately on screen rotate it's not resized (please see below):
How can I make sure that screen is resized on screen rotation.
If it's iOS, then make a custom WebView renderer (http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/):
protected override void OnElementChanged (VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
ScalesPageToFit = true;
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
NativeView.Bounds = UIKit.UIScreen.MainScreen.Bounds;
}
Please try this solution, it works in iOS 8.4, but not iOS 7.
Xamarin Forms: How to resize the Webview after rotation in iOS
You need to be working with webview using Xamarin.forms.
Working with WebView in Xamarin.Forms
xamarin-forms-samples/WorkingWithWebview Has examples for each platform.
This link on Handling Rotation gives you all the details you need for android. The other answer has covered iOS.
Responding To Orientation Changes In Xamarin Forms another great link
Customizing Controls for Each Platform using these premise you can manage the screen rotation for each platform separately within the one app.
Handling Runtime Changes shows how to manage screen rotation. You need to scroll down the page.
A good link on managing windows phone, The two ways to handle orientation in your Windows 8.1 app.
Another useful link Fix IE 10 on Windows Phone 8 Viewport.
This is an interesting link on Managing screen orientation from mozilla. It is experimental, but interesting.
I implemented the custom renderer and added the line "webView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;" but it doesn't work for me. Then, I solved this with a not so elegant solution (reloading the WebView component when the device orientation changes).
In my xaml:
<StackLayout Padding="0" >
<WebView x:Name="viewJupyter" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" />
</StackLayout>
And my code behind class:
public partial class ServiceChart : ContentPage
{
private int _rotateView;
public ServiceChart(string title, string url)
{
Title = title;
InitializeComponent();
var urlPage = new UrlWebViewSource
{
Url = url
};
viewJupyter.Source = urlPage;
if (Device.OS == TargetPlatform.iOS)
{
SizeChanged += (sender, arg) =>
{
if (_rotateView != 0)
{
var lalala = viewJupyter;
InitializeComponent();
viewJupyter.Source = (lalala.Source as UrlWebViewSource).Url;
}
_rotateView++;
};
}
}
}
I make code to Blackberry Storm. When my application in horizontal display (480x360), it's work. But when the Blackberry tilt into Vertical (360x480), the picture is cut off. So I was asking how to set up so that at the time of rotation, also resize the picture? is there any method to check if BlackBerry again horizontal or vertical display?
Thanks.
Here are two things, either you will lock screen orientation or you will support in your application.
Code sample: Retrieving screen orientation
switch(Display.getOrientation())
{
case Display.ORIENTATION_LANDSCAPE:
Dialog.alert("Screen orientation is landscape"); break;
case Display.ORIENTATION_PORTRAIT:
Dialog.alert("Screen orientation is portrait"); break;
case Display.ORIENTATION_SQUARE:
Dialog.alert("Screen orientation is square"); break;
default:
Dialog.alert("Screen orientation is not known"); break;
}
Code sample: Forcing portrait view in a BlackBerry API application
// Use code like this before invoking UiApplication.pushScreen()
int direction = Display.DIRECTION_NORTH;
Ui.getUiEngineInstance().setAcceptableDirections(direction);
You you want to handle the images and other graphics setup on orientation change then you can do the following changes in your code.
Override the sublayout method, in your MainScreen subclass.
protected void sublayout(int arg0, int arg1) {
// do all the
super.sublayout(arg0, arg1);
}
Check for the orientation changes, rearrange the UI. Usages of relative layout is recommended for such things.
Hope, this might help you out. For more info visit Specifying_display_direction_of_screen
Edit: override sublayout() and then write the code specific to orientation
public void sublayout(int width, int height) {
switch(Display.getOrientation())
{
case Display.ORIENTATION_LANDSCAPE:
// write the piece of code for refreshing the screen UI which screen orientation is landscape
break;
case Display.ORIENTATION_PORTRAIT:
// write the piece of code for refreshing the screen UI which screen orientation is portrait
break;
}
super.sublayout(width, height);
}
Edit 2:
you were going wrong because of UI event lock, now you do the following changes to your code.
public void sublayout(int maxWidth, int maxHeight) {
int displayWidth = deviceWidth;
int displayHeight = deviceHeight;
switch (Display.getOrientation()) {
case Display.ORIENTATION_LANDSCAPE:
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Screen orientation is landscape");
// here you need to change your uI code as you want to do in for landscape mode
// you may need to delete and add the UI comps manually
// if the components added to absolute layout then just refresh the screen it will auto adjust with your new screen size
}
});
break;
case Display.ORIENTATION_PORTRAIT:
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Screen orientation is PORTRAIT:");
// here you need to change your uI code as you want to do in for PORTRAIT mode
// you may need to delete and add the UI comps manually
// if the components added to absolute layout then just refresh the screen it will auto adjust with your new screen size
}
});
break;
}
super.sublayout(displayWidth, displayHeight);
setExtent(displayWidth, displayHeight);
}
Well I faced this problem before and solved it. The solution is not to "oblige the blackberry screen not to rotate". I made this before and it is annoying. Well the solution to this is override the subLayout method of the main screen and all the managers included in the main screen. This method is always called when a rotation occurs.
Your code will looks like follows:
public void sublayout(int width, int height) {
changeImage(); // this method will change your image x and y and then draw it again
super.sublayout(width, height);
}
I have to add image on the header and background . Is it possible to set the image automatically resizing according to the screen orientation (portrait and Landscape). I set the image in portrait resolution , But when i change the screen to Landscape the image not resized. Can anyone give me some guidelines?
Support for this is built into jQuery Mobile. There are two Orientation Classes which are present depending on the current screen orientation:
.portrait {
/* portrait orientation changes go here! */
}
.landscape {
/* landscape orientation changes go here! */
}
Or if you want a javascript event you can bind to orientationchange.
I don't think there are events that get triggered when the phone goes for landscape to portrait.You can however write a custom function to find out the current orientation. Write the following code on window.resize event.
$(window).resize( function(){
var height = $(window).height();
var width = $(window).width();
if(width>height) {
// Landscape
$("#img").attr("src","landscapeurl");
} else {
// Portrait
$("#img").attr("src","portraiturl");
}
});
code from Here
It's recommended to use CSS3 media queries as the jQuery mobile orientation classes are deprecated: http://jquerymobile.com/demos/1.0b2/docs/api/mediahelpers.html
For a demo of CSS3 media queries: http://www.webdesignerwall.com/demo/media-queries/
i use this css3 rule:
#media (orientation: landscape) {
#home-feature span {
display : inline-block;
}
}
more info: http://www.w3.org/TR/css3-mediaqueries/