ZBar for landscape orientation in iPad - ios

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.

Related

Support Orientation Change On Some of UI but Not All

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 ...

ios7 and ios8 landscape modes - part of the screen doesn't response

I'm developing an application in iOS8 in landscape mode and everything works fine. I'm using UIKit and don't support portrait mode at all.
Im trying to customise it to iOS7 but the frame that I'm getting is always like the iPhone is in a portrait mode.
I know that the in iOS8 there was a major change with the width and height and it's different in iOS7.
I have the following method which I used to set the window n the appDelegate and when I need the frame at the ViewControllers.
I'm doing the following:
- (CGRect) screenRect {
CGRect screenRect = [UIScreen mainScreen].bounds;
if ((NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
return CGRectMake(0,0,screenRect.size.height, screenRect.size.width);
}
return screenRect;
}
The views look fine but the left/right side of the screen (depends on the device orientation) behaves like it's outside the frame. i.e doesn't response to gestures!
When I'm setting the fame to the new "screenRect" it keeps turning back to the device bounds.
Thank you very much.

how is Core-plot supporting portrait to landscape transitions

Have been looking at the latest version of Core-plot ce0fa44812 and the associated example code.
It supports device orientation, however I am unable to determine the mechanism used to provide this support. I see the orientation options provided in the plist.
In particular I am interested in the Real Time plot example, however see no calls to change the bounds upon rotation from portrait to landscape.
So what magic is going on here? There are the bounds being changed.
That version of the Plot Gallery example app uses a storyboard with the new iOS 8 split view controller to manage all layout and transitions. The views in each storyboard scene use auto layout to resize automatically when needed.
You can change the frame of hostingView when the device rotate.
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator: (id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self.hostingView setFrame:[self.view bounds]];
}];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
Then you will change to the landscape plot.
If you want to your device is held in portrait before you plot the graph.
You need to set the view controller. Otherwise, there is something like a bug, that the plot is set in portrait size in a landscape mode.
-(void)viewDidLayoutSubviews {
[self.hostingView setFrame:[self.view bounds]];
}

iOS5, iOS6, rotation, event firing arbitrarily

I have an app that supports orientation changes and rotates accordingly. I listen to the event UIApplicationWillChangeStatusBarOrientationNotification. Now during the load of this app I add some views and set them up in my app, based on the current orientation.
in iOS 6, this works fine and the app responds and rotates properly, so the user can load in both landscape and portrait mode and code works fine.
in iOS 5, if I load the app in portrait mode, the app works fine, and once that load has been completed in portrait mode, and the UI is aligned and sized, it will respond to other orientation changes to landascape or portrait. The problem I have is this : When loading iOS 5 in landscape mode, and while physically laying the device with iOS 5 on a flat surface to ensure its landscape, I get a OrientationNotification that moves from Landscape to portrait ( although the device didn't change ).
So another device iOS 6 in the same experiment, loads properly and I don't get any weird events of rotation changes that didn't occur, but with iOS 5 I do get them!!
Any ideas?
I am supporting the orientation for both iOS's
- (BOOL)shouldAutorotate {
return YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
It sounds like iOS 5 believes things should be portrait if, in fact, there is no physical orientation (i.e. flat up or down) and iOS 6 doesn't. For what it might be worth, to determine the orientation to display stuff when it matters, I use the actual device orientation when available and the status bar orientation when the device is flat. For instance:
// Get a useful screen orientation.
// If the device is physically in portrait or landscape then
// that is the orientation.
// If it is not, then it is probably flat on a table and use
// the orientation of the status bar which should be set to
// the last physical orientation.
//
// screen Orientation
//------------------------------------------------------------
+ (UIDeviceOrientation) screenOrientation {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation!=UIInterfaceOrientationPortrait
&& orientation!=UIInterfaceOrientationPortraitUpsideDown
&& orientation!=UIInterfaceOrientationLandscapeLeft
&& orientation != UIInterfaceOrientationLandscapeRight) {
// Not known at this time. Use the status bar orientation
orientation = [[UIApplication sharedApplication] statusBarOrientation];
}
return orientation;
}
I'm not sure that helps you directly, but perhaps in your notification handler you could check to see what the actual status bar orientation is. Or maybe the timing of the notification and the status-bar orientation change doesn't make that work.

iPad stop screen from Rotating Xcode 4

I am building an iPad app in Xcode 4. The app is suposed to always show in Landscape view. to achieve this I have tried the following:
In the Target summary screen I selecte only Landscape Left as a Supported Device Orentation.
In the Target Info screen / Info.plist set the Supported interface orientations(iPad) to Landscape (left home button)
This leads the app the to start in landscape mode, but if I rotate the device it still changes its orientation. Also, when I have a UIViewController presented with presentationStyle UIPresentationFormSheet it rotates to portrait the moment it shows.
In some other threads / forums it was adviced to create a category for UIViewController and rewrite
-(UIDeviceOrientation)interfaceOrientation;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
To always rotate to the Device Orientation (LandscapeLeft) or specifically LandscapeLeft, also to no AutoRotate unless you rotate to LandscapeLeft.
When I set these functions like this (Or for example allow no rotation at all) the app always appears in portrait mode, and wont rotate, not even to LandscapeLeft. The only way to have the app start in Landscape mode is when I allow for rotation no matter what the interfaceOrientaton is.
Does anybody know how I can fix this?
The category I implemented:
#implementation UIViewController(Extends)
-(UIDeviceOrientation)interfaceOrientation
{
return [[UIDevice currentDevice] orientation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
return YES;
else
return NO;
}
#end
The only place that I can find a Portrait Orientation to be defined is the original window on the MainWindow.xib, but this cannot be altered, and every thread/forum says that that particular setting is/should not be the issue.
As far as I can tell the steps you took should prevent rotation of the interface.
You can always try to override the calls that do the orientation in every viewcontroller of your app. That should at least give you a clue where the rotation is happening. After which a breakpoint can possibly tell you more.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
NSLog( #"will rotate to orientation %d in %#", interfaceOrientation, NSStringFromClass([self class])
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
NSLog( #"did rotate from orientation %d to %d in %#", fromInterfaceOrientation, [self interfaceOrientation], NSStringFromClass([self class])
}

Resources