FGallery is overriding all rotation methods in my other views - ios

So I have incorporated Mr. Grant Davis' FGallery into my app for a photo gallery. It works great other than it is overriding all my rotation methods in my other views and I cannot for the life of me figure out how to stop it. Here's a snippet from FGallery's FGalleryViewController that handles the gallery:
#implementation UINavigationController (FGallery)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([self.visibleViewController isKindOfClass:[FGalleryViewController class]]) {
return YES;
}
// we need to support at least one type of auto-rotation we'll get warnings.
// so, we'll just support the basic portrait.
return ( interfaceOrientation == UIInterfaceOrientationPortrait ) ? YES : NO;
}
I have tried changing the line:
return ( interfaceOrientation == UIInterfaceOrientationPortrait ) ? YES : NO;
but that forces all views to that specific orientation. Some of my views allow for rotation and some do not. So I guess my question is, how can I alter this line to allow rotation in some views and not in others? I'm drawing a blank this morning!!
Any help or ideas here would be appreciated!!

So I'm gonna go ahead and answer my own question.
The answer is to remove the code that overrides the rotation:
#implementation UINavigationController (FGallery)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if([self.visibleViewController isKindOfClass:[FGalleryViewController class]])
{
return YES;
}
// we need to support at least one type of auto-rotation we'll get warnings.
// so, we'll just support the basic portrait.
return ( interfaceOrientation == UIInterfaceOrientationPortrait ) ? YES : NO;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
// see if the current controller in the stack is a gallery
if([self.visibleViewController isKindOfClass:[FGalleryViewController class]])
{
FGalleryViewController *galleryController = (FGalleryViewController*)self.visibleViewController;
[galleryController resetImageViewZoomLevels];
}
}
#end
And call:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
within #implementation FGalleryViewController
Hopefully this helps someone else out that needs it.

Related

Possibility Portrait mode in 1 UIView

Is there a possibility that I can programatically say that only 1 UIView can be in landscape mode?
My Whole app has to be in portrait mode (not moving at all) but 1 UIView should be able to go in Landscape mode (To show pictures even better);
You rotate VC like this:
- (BOOL)shouldAutorotate {
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations {
return self.topViewController.supportedInterfaceOrientations;
}
Restrict VC so it won't rotate:
- (BOOL)shouldAutorotate { return NO; }
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskPortrait);
}
You could change condition as per your need and this answer is referred from this link so you could go there for more understanding.
Also do keep that iOS 6/7 have different method for checking.If anything else then let me know.
UPDATED:- iOS 7 callBack method for checking mode
– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– didRotateFromInterfaceOrientation:

ZBarReaderViewController reader view changes orientation for iOS6 & iOS7 even after restricting it by _reader.supportedOrientationsMask

I am using ZBarSDK for QR Code scanning feature. I want to use this only in PORTRAIT mode only. As per the documentation I set it up with below code line:
_reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);
As expected it works well with iOS 5 but with the same code this view changes orientation for iOS 6 & 7. Is supportedOrientationsMask only works with < iOS 6? Is there any other way to force this ZBar reader camera view to work only in Portrait mode? Thanks in advance
Here more details with Code:
if(_reader) // first check `_reader` is created or not?
{
[_reader.readerView stop]; // then stop continue scanning stream of "self.ZBarReaderVC"
for(UIView *subViews in _reader.view.subviews) // remove all subviews
[subViews removeFromSuperview];
[_reader.view removeFromSuperview];
_reader.view = nil;
}
_reader = [ZBarReaderViewController new];
_reader.readerDelegate = self;
_reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);
ZBarImageScanner *scanner = _reader.scanner;
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
[_reader.view setFrame:CGRectMake(0, _topbar.frame.size.height, self.view.bounds.size.width, self.view.bounds.size.height-_topbar.frame.size.height)];
_reader.cameraOverlayView = [self CommomOverlay];
_reader.showsZBarControls=NO;
// present and release the controller
[self presentModalViewController: _reader
animated: NO];
Let me know in case more details required.
Finally found the solution.
The problem was like this:
ZbarViewController *reader was presented from my current view controller and it's portrait support property was not working somehow.
_reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);
What i did to resolve this issue is I created TBZbarViewController the new class which was inheriting the ZbarViewController class and placed the below method.
-(BOOL)shouldAutorotate{
return NO;
}
Then I used the TBZbarViewController *reader to present from My controller which solved the issue and it's working in Portrait mode only as needed.
Thanks.
I did like this, and is working for all iOS versions :
Step 1 : Set your Device Orientation
Step 2 : Add this code into you implementation (.m) file.
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
- (BOOL) shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskPortrait;
}
#endif
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

Camera Image Picker controls - Auto Rotation in iOS7

I have a photo app that overlays custom button on camera image picker (for taking picture, turning on/off the flash, other usual stuff etc.)
I want the control interface to support portrait orientation only (I am talking about the control button/interface only, and not the actual captured image), which was working fine till iOS 6.
However, having upgraded to xCode version 5.0 and having upgraded my iPad 3 to iOS 7 (GM Seed, for iPad WiFi 3rd Generation), I find that the camera picker interface auto-rotates when orientation is changed. Surprisingly, I tested the same build on an iPhone 5 (upgraded to iOS 7), but the auto-rotation problem did not manifest itself.
[To be double sure, I tested the same piece of code in iOS 6 again, and the auto-rotation did not happen, neither in iPhone or iPad].
Just to demonstrate how I handle my image picker, here's a bit of code snippet:
UIImagePickerController *pickercustom = [[UIImagePickerController alloc] init];
pickercustom.sourceType = UIImagePickerControllerSourceTypeCamera;
pickercustom.showsCameraControls = NO;
pickercustom.wantsFullScreenLayout = YES;
pickercustom.navigationBarHidden=YES;
pickercustom.view.userInteractionEnabled=YES;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
if (IPAD.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
pickercustom.delegate = self;
UIDevice *currentDevice = [UIDevice currentDevice];
while ([currentDevice isGeneratingDeviceOrientationNotifications])
[currentDevice endGeneratingDeviceOrientationNotifications];
[self presentViewController:pickercustom animated:YES completion:nil];
while ([currentDevice isGeneratingDeviceOrientationNotifications])
[currentDevice endGeneratingDeviceOrientationNotifications];
}
else
{
pickercustom.delegate = self;
[self presentViewController:pickercustom animated:YES completion:nil];
}
}
The 'endGeneratingDeviceOrientationNotifications' was added to stop the interface from rotating (which hitherto worked fine).
I also tried adding these three methods after reading this: UIImagePickerController in iOS 6 doesn't work properly
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
...but this was, perhaps, an iOS 6 specific solution. It didn't work in my case.
Please let me know if you could figure out the root cause. It would be great help.
You are close. When you want to support rotation but want that one viewController to not rotate, things get tricky:
The UIResponder chain REALLY wants the whole app to have the same rotation. Just simply overriding the rotation delegate methods in your single class will not work. (FYI, in your case, you will need to subclass UIImagePickerController in order to add those methods.) You need to implement these delegate methods in your root navigation controller (You'll need to have your own sub-class, again), and override them to query the top-most viewController for its desired rotation. Something like:
// Handles the should Auto Rotation for all view controllers
- (BOOL)shouldAutorotate {
if ([self.topViewController conformsToProtocol:#protocol(CustomRotation)]) {
return [self.topViewController shouldAutorotate];
}
// Auto rotate the screen by default.
return YES;
}
// Handles the supported Interface Orientations for all View Controllers by seeing if
// the top level viewController responds to Custom Rotation callbacks.
- (NSUInteger)supportedInterfaceOrientations {
if ([self.topViewController conformsToProtocol:#protocol(CustomRotation)]) {
return [self.topViewController supportedInterfaceOrientations];
}
// The default rotation for the application.
return UIInterfaceOrientationMaskAll;
}
You can't use respondsToSelector: in place of conformsToProtocol: because the selector method will always return YES for any class that derives from UIResponder (so like, everything), and you'll have to override the rotation delegates on each and every UIViewController in your project to make this work. Instead, you can create a blank protocol (CustomRotation). In your custom rotation class require that protocol and include the overridden rotation delegate methods like you have above, with the your desired restrictions.
Lastly make sure your supported interface orientations are set properly in xcode and/or in your Application: didFinishLaunchingWithOptions method.
As far as R&D done by me for the same topic,Imagepicker Camera in IOS7 iPad have default interface to change orientation to landscape .They have designed interface in such a way.We cannot forcefully lock the orientation of it.
If still willing to do you have to use custom ImagePicker use AVCam https://developer.apple.com/library/ios/samplecode/avcam/Introduction/Intro.html
and Custom image picker...
http://www.codza.com/custom-uiimagepickercontroller-camera-view
and forcefully lock there orientation...

Specific Orientation Background

Here my code for specifying the background in ipad iOS6,
- (void)viewDidLoad
{
if ([[UIScreen mainScreen] bounds].size.height == 1024)
{
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"homeipad.png"]];
}
else if ([[UIScreen mainScreen] bounds].size.height == 768)
{
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"landscapipad.png"]];
}
}
its not changing depends on orientation?I have included
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
How to allocate specific background image for corresponding orientation in ipad?
Remember viewDidLoad is called only when you make a new UIViewController object in the memory and you push/present that controller object.
the method name viewDidLoad defines that your viewcontroller view is loaded. Now you can perform the all initialization tasks here.
Answer to your question.
The following UIVIewController's delegate methods will help you in this. These methods are called every time when device changes its orientation.
// Called before interface rotation
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
// Called after interface rotation
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
One more thing, rather than comparing screen height , you can check the current orientation from the above two methods.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
{
if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{
// Your code goes here for landscape orientation
}
else
{
// Your code goes here for portrait orientation
}
}

Autorotation in iOS 6.1 for custom camera view

I've read almost every post around here regarding my problem but none of the solutions seems to work on my app.
So, I use a custom camera view (with buttons on toolbar and an overlay) that is being presented modally from a view controller. My app only supports landscape left and right for the orientation. And i want to stop the camera view from autorotating when it's being presented. I've put all the methods needed for autorotation on my view controller and my app delegate. I've checked on my plist file too and the supported rotations are correct. But my camera view keeps on rotating to any rotation (portrait and landscape) when I rotate the device, resulting on the overlay and the toolbar being incorrectly positioned. I also can't check on the camera view's orientation because i tried putting NSLog on shouldAutoRotate method, but it doesn't get called at all.
So how can I check the rotation on my custom camera view? And how can I force it to not rotate and stay still?
If my code is needed, I'll post it here. If anyone can help me on it I'll greatly appreciate it because it frustrates me so much right now.
Thank you. Cheers.
Create a new class of "UIImagePickerController" and implement the rotation delegates in the .m file as given,
// For lower iOS versions
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || ((toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)));
}
// For iOS version 6.0 and above
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskLandscape);
}
And make an instance of lets say MyImagePickerController instead of UIImagePickerController, and present it. This will work :)
Create a category for UINavigationController
#interface UINavigationController(autoRotation)
-(BOOL)shouldAutoRotate;
#end
#implementation UINavigationController
-(BOOL)shouldAutoRotate{
return [[self.viewControllers lastobject] shouldAutoRoatate];
}
-(NSUInteger)supportedInterfaceOrientations {
return [[self.viewControllers lastobject] supportedInterfaceOrientations];
}
#end
Implement these two methods in your corresponding view controllers
and return the orientation what u exactly want....
xcode -> file -> new file select cocotouch in the leftpane select objective-c category ->next
select give name Picker category on UIImageImagePickerController from dropdown
import
#interface UIImagePickerController (picker)
-(BOOL)shouldAutoRotate;
-(NSUInteger)supportedInterfaceOrientations;
#end
import "UIImagePickerController+picker.h"
#implementation UIImagePickerController (picker)
-(BOOL)shouldAutoRotate{
return yourOrientation;
}
-(NSUInteger)supportedInterfaceOrientations {
return yourInteger;
}
#end
After this when your device's orientation changed then the method shouldAutoRotate get called from your UINavigationController category at this time you have to find out if cameraview is presented if yes then you have to call shouldAutoRotate of Picker
See the following code
in your view controller's shouldAutoRotate
-(BOOL)shouldAutoRotate{
if([self presentingViewController])// Camera is present
return [instanceOfUIImagePickerController shouldAutoRotate];
return yourOrientaionNeededForThisVC;
}

Resources