I have written an Augmented reality app for iOS which uses location services and GPS, everything works fine when the device is in landscape left but when the devices rotation is landscape right the center azimuth does not get calculated correctly, I am currently calculating this using the true heading in the didUpdateHeading method the subtracting a heading adjustment of 90 degrees. Should I be checking if < 0??
Thanks.
This is a pretty annoying issue and it seems that setting the headingOrientation property doesn't actually do anything.
The code below works for a landscape left orientation (home button on the right):
orientation = (float) manager.heading.magneticHeading;
orientation += 90.0f;
if(orientation > 360.0f)
orientation -= 360.0f;
So for a landscape right orientation, this should do the trick:
orientation = (float) manager.heading.magneticHeading;
orientation -= 90.0f;
if(orientation < 0.0f)
orientation += 360.0f;
Related
I am making a drawing app and I would like the user to be able to rotate their device and draw on the canvas in any orientation. The toolbar of brushes/colors/etc needs to change orientation to always be on the top of the screen HOWEVER the drawing canvas needs to NOT change orientation (so as to preserve the drawing's orientation; imagine rotating a piece of paper with a drawing on it - the drawing would sometimes be sideways or upside down but your pencils would be still right in front of you).
I have tried several attempts and have concluded that I DO want to support iOS's default orientation changes because things like UIAlert popups need to be oriented correctly. Implementing override var supportedInterfaceOrientations: UIInterfaceOrientationMask on the view controller is not the best option.
I have gotten closer by subscribing to device orientation changed notifications and rotating the drawing canvas in the opposite direction to compensate for the default UI orientation rotation. In this case I am applying a CGAffineTransform rotation of 90, -90, 0, or 180 degrees to the canvas container view but its subviews are not rotating correctly with it.
Any ideas that I may be missing to get the behavior I want?
This is what I want. Notice how the toolbar is always being oriented to the top after rotation but the drawing stays glued to the device.
Before orientation change:
After orientation change:
I did a quick test app to see if what you experienced (with regards to rotating the canvas view and not having its subviews rotate as well) and I cannot replicate what you're seeing.
I simply have an observer set up on viewDidLoad from the main view:
NotificationCenter.default.addObserver(self, selector:#selector(self.orientationChanged(_:)), name: NSNotification.Name.UIDeviceOrientationDidChange, object:nil)
And the orientation change notification is handled like this:
func orientationChanged(_ n:Notification) {
let orientation = UIDevice.current.orientation
if orientation == UIDeviceOrientation.portrait {
// No rotation
vwCanvas.transform = CGAffineTransform(rotationAngle:0)
} else if orientation == UIDeviceOrientation.portraitUpsideDown {
// Rotate canvas 180 degrees
vwCanvas.transform = CGAffineTransform(rotationAngle:CGFloat.pi)
} else if orientation == UIDeviceOrientation.landscapeLeft {
// Rotate canvas 90 degrees counterclockwise
vwCanvas.transform = CGAffineTransform(rotationAngle:CGFloat.pi/2.0)
} else if orientation == UIDeviceOrientation.landscapeRight {
// Rotate canvas 90 degrees clockwise
vwCanvas.transform = CGAffineTransform(rotationAngle:-CGFloat.pi/2.0)
}
}
Here's my portrait orientation screen:
And here's the rotated version:
As you'll notice, the sub-views are rotated in the above too. So just wondering what the difference is between my version and yours (since I don't know what your code is like) that you don't have the subviews rotate when you rotate the canvas ...
I am developing a landscape application with orientation UIInterfaceOrientationMaskPortrait, except one view controller( used for uploading image) having orientation UIInterfaceOrientationMaskLandscapeRight.
How orientation change should ideally work
When users plan to upload image, orientation change from UIInterfaceOrientationMaskLandscapeRight to UIInterfaceOrientationMaskPortrait,
When uploading finished, change orientation UIInterfaceOrientationMaskPortrait to UIInterfaceOrientationMaskLandscapeRight, .
Issue:
When I tap the icon then into the application, the application layout is right, but if I flat device on the desk for times, next time I get into, application layout is wrong.
For example:
First time:
aView.width = 568 * 0.6;
aView.height = 320 * 0.6;
but in other cases:
aView.width = 320 * 0.6;
aView.height = 568 * 0.6;
seems like width and height exchanged
Suggestions are appreciated!
I an new at Sprite kit and I want to add some node to scene.
My problem is positions :
If I put :
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:#"Poligon"];
sprite.xScale = 0.5;
sprite.yScale = 0.5;
sprite.position = CGPointMake(40, 400);
it looks right when iPhone is in landscape mode, but when it is in portrait it disappear from the screen.
My guess is that it take coordinate from landscape and put it at right side of the screen. This would explain why node is not visible in portrait mode.
My question is how to set that iPhone would take portrait mode by default?
Apparently sprite kid start in landscape mode and take start viewDidLoad before it take rotation in account. Because of this the coordinate system in portrait mode is shifted, even if you set orientation to portrait.
The solution according to :
http://www.ymc.ch/en/ios-7-sprite-kit-setting-up-correct-scene-dimensions
is to set your scene not on viewDidLoad but on
- (void)viewWillLayoutSubviews
This is run after orientation is set and it works.
How to get the screen width and height only in landscape orientation , i have two ipad 4 tablets and on one of them it takes me the landscape width & height , and on the other one it takes me the portrait one even if it's orientation is on lanscape
at the moment i am using this but its not working well
CGFloat width = self.view.bounds.size.width;
CGFloat height = self.view.bounds.size.height;
Use [UIScreen mainScreen].bounds you'll have the same.
Discussion
This rectangle is specified in the current coordinate
space, which takes into account any interface rotations in effect for
the device. Therefore, the value of this property may change when the
device rotates between portrait and landscape orientations.
Use [UIScreen mainScreen].nativeBounds in iOS8 only to get the portrait-locked bounds.
Discussion This rectangle is based on the device in a
portrait-up orientation. This value does not change as the device
rotates.
Swift 3
let pixelWidth = UIScreen.main.nativeBounds.width
let pixelHeight = UIScreen.main.nativeBounds.height
let pointWidth = pixelWidth / UIScreen.main.nativeScale
let pointHeight = pixelHeight / UIScreen.main.nativeScale
print ("Pixels: \(pixelWidth) x \(pixelHeight)")
print ("Points: \(pointWidth) x \(pointHeight)")
On a 6s Plus will print...
Pixels: 1080.0 x 1920.0
Points: 414.0 x 736.0
I've worked on the Zbar in iPhone and also in iPad, it works fine without any issues, but not with the landscape mode in iPad. When I present the ZBarReaderViewController in iPad with a popover in landscape mode, the view is 90 degree shifted as in the below image,
where the bag is on the table and the image is captured with iPad in landscape mode. I want the bag image not as shifted.
I've already tried setting the supportedOrientationsMask as
reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationLandscapeLeft || UIInterfaceOrientationLandscapeRight);
But its not showing in the correct orientation, but is a 90 degree shifted. Can someone help me solve this issue? Any timely help is much more appreciated. Thanks.
I had almost the same issue, and I got it resolved by adding the below code. My app supports only Landscape orientation:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIDeviceOrientationLandscapeLeft == orientation) {
//Rotate 90
reader.cameraViewTransform = CGAffineTransformMakeRotation (3*M_PI/2.0);
} else if (UIDeviceOrientationLandscapeRight == orientation) {
//Rotate 270
reader.cameraViewTransform = CGAffineTransformMakeRotation (M_PI/2.0);
}
The thing with this solution is that is fixes only the visual part of the problem. The user sees the right orientation, however the ZBarReader still 'sees' the same image, because you're transforming the preview image. What works is this:
[self.readerView willRotateToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] duration:0];
in the viewDidLoad method of your ViewController containing the ZBarReaderView.