Call a function when orientation changes - orientation

I want to call a function when orientation goes from portrait to landscape and vice versa.
I thought this would be very easy but having searched for hours and tried many versions out there I can't get this to work.
For simplicity's sake lets say I want to call a function called "change" when orientation changes and I want to do this in as few lines as possible in tags directly in the HTML.

I think this should work...
window.addEventListener("orientationchange", change);

Related

Update status bar text colour in real time as view changes

This might be a beginner question, but I noticed something interesting in the new Apple Music app. When switching from one view to another, the status bar text colour seems to change in real time rather than all at once when the next view loads.
Check out this screen recording to see what I mean:
http://f.cl.ly/items/2A0a3Q3i2O2d2O3u3q1m/statusBar_1.mp4
Closeup: http://f.cl.ly/items/182r3n3Z1m1y0y1W0j2J/statusBar_2.mov
How would I achieve this same effect? For instance, when transitioning to another view controller modally, how would I get the status bar style to change dynamically like this rather than when the next view loads? Is it even possible? Is Apple using some private API, or is it just a really simple trick I'm missing? Sorry if this is a beginner question, but I don't think I've ever seen another app do this.
Nothing you’re missing—there’s definitely no API to do that. I’ve seen a couple of third-party apps do something similar, probably by finding the status bar window, snapshotting it, and doing clever things with the resulting image, but that’s pretty fragile. As always, if you’d like an API for something, you should file an enhancement request.

Rotate VCL components in Delphi XE2

Now I adapt my app for tablet PC. I ask how can I fixate form when the screen was rotated. Good people says that I must adapt my app for portrait orientation and they're right.
Some forms is very specific and it's very hard (maybe impossible) to re-design they for portrait orientation. So I think I can create a illusion that my app works only in landscape orientation.
That's why I need rotate standard VCL components in Delphi XE2. For example for standard memo I need write text not only from left to right (or right to left) and from up to down (and from down to up).
Also I need rotate button. Now I use standard TButton and TRxSpeedButton.
I think enough to rotate the text for TButton but I don't know how I can do this?
In case of TRxSpeedButton I use glyphs. In theory maybe I can override canvas and change pic. Another way is create 2 buttons (one for portrait orientation, one for landscape. Each one will have their special glyph) and change their visibility. But I don't like 2nd variant because in this case exe file will be very plump, I don't like plump exe))
Thanks for advises.
You've no realistic chance of making this work using standard VCL controls. VCL controls don't have a mode that allows them to be rotated through 90 degrees. I see no easy prospect for making any control that displays text do so rotated. That's just text output. What about text input? There's also the issue of shadows and 3D effects which are based on a specific orientation. The list goes on and on.
In my view, if you want to make this work well you'll almost certainly need to write an entire GUI framework from scratch.
Whilst it is clear possible to do this it doesn't seem like a realistic choice when set aside the alternative of making your app work in both portrait and landscape orientations.
You have no chance with fake landscape approach.
There are three solutions for your problem:
Best one - make your application work with any screen size / orientation combination. This is the Windows way.
If your application "must" work in landscape mode, inform users when you detect wrong orientation, that application only functions in landscape mode. Show either message box, or special form with message that cannot be missed, while you hide your other forms, or something like that.
Lock device in landscape mode, like described in How to prevent the screen from automatically rotating on a tablet? But you should know that this is not the way Windows are meant to be used in Desktop mode.
The VCL was not built for this, so I dont really see that happening without major work done to the presentation layer of the RTL.
The have been skinning engines that were capable of this, but they essentially patched the RTL and took over rendering. Rotation data was held in a lookup table for each control that you had to set separately from the actual class.
If Delphi had support for partial classes like Smart Pascal does, then perhaps (if the architecture allowed it) this could be postfixed. But as of writing the VCL is simply not made for this. I am writing a tweening library as I type this, so I have looked into this.
One way that might work for you would be to use the PaintTo method of various controls. Have them paint their fully drawn image onto a bitmap and then rotate the bitmap by 90 degrees to get the portrait versus landscape effect. Then draw that image on the canvas of your form in its OnPaint method (you would want to make the actual controls invisible when in the portrait mode, showing only your painted and rotated bitmaps.)
There are some controls (like TRichEdit) whose PaintTo Method doesn't work correctly, though. So this may be of limited use for you. Another way is to grab a screen capture of the entire client area of the form on the desktop and then rotate and display that. that works even with TRichEdit...

iOS Maps UIPopover misplaced after orientation change

we are working on a tablet app and have the following problem:
We are using popover controllers if the user touches a pin on the map but after orientation change, the popover is misplaced. But we cannot keep a reference because after orientation change, the pins are reloaded.
Did someone already have this problem and found a generic solution for this? I wonder how apple is handling this.
Generally the placement of popovers after orientation change is sometimes acting a bit strange.
thanks in advance
A common approach is closing the popover after rotation. Unfortunately there's not going to be much you can do that wouldn't require some complicated repositioning logic. Perhaps store the origin point as an iVar and calculate the new coordinates based on the new orientation. There's no generic solution for this, however.

How to start a landscape iOS app in the correct orientation without rotating?

I'm developing a landscape-only, iPhone-only iOS6+ app and having problems getting the rotation to work as I want it to.
The only supported interface orientations set for the app target are Landscape Left and Right. I only have a single view controller at the moment, with its -supportedInterfaceOrientations method simply returning UIInterfaceOrientationMaskLandscape. The info.plist file does not have the UIInterfaceOrientation key.
What I'd like to happen is that after the launch image disappears and the initial view controller is displayed, it is immediately displayed correctly in the orientation in which the user is holding the device, no animations.
What is happening instead is that if the user holds the phone with the home button on the right, the interface is drawn upside down, and then autorotated to match the device rotation. The phone automatically prefers one landscape mode over the other, and I need it to prefer neither (or at least APPEAR to prefer neither, even if this means the use of trickery is needed.)
This question seems to be asking the same thing, although the use case there is somewhat different, and it's unanswered.
What do I need to do to achieve this?

iOS: Fix/lock Camera View in Portrait Mode/Orientation

I'd like to fix my Camera View in Portrait Mode but I found NO solution till now...
Do YOU have one? Would make my day .__.'
You cannot explicitly restrict the UIImagePickerController to portrait mode, but you can customize the look of the camera's user interface, which may help you. This is the example code from Apple:
https://developer.apple.com/library/ios/#samplecode/PhotoPicker/Introduction/Intro.html
Another method of controlling the camera's look is mentioned in this question:
Camera with Custom View
I don't know exactly what your goal is, but one of these methods should help.

Resources