Enable rotate for mwphotobrowser in portrait app - objective-c

I have a fixed portrait app using objective-c, and i have a button click for open MWPhotoBrowser for browsing images. Now It works well in portrait mode but I want to make the MWPhotoBrowser for both portrait and landscape mode for rotate the phone. How can I do that, here is my code:
- (void) prepareForPhotoAlbum:(NSArray*)photoObjs {
self.photoURLArrays = [[NSMutableArray alloc]init];
for(int i=0 ; i<photoObjs.count ; i++){
NSDictionary* dictOfImageObj = photoObjs[i];
[self.photoURLArrays addObject:[MWPhoto photoWithURL: [NSURL URLWithString:[NSString stringWithFormat:#"%#/%#",ServerTopicImageURL,dictOfImageObj[#"filename"]]]]];
}
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
// Set options
browser.displayActionButton = YES;
browser.displayNavArrows = NO;
browser.zoomPhotosToFill = YES;
[browser setCurrentPhotoIndex:0];
browser.wantsFullScreenLayout = YES;
[self.navigationController pushViewController:browser animated:YES];
[browser showPreviousPhotoAnimated:YES];
[browser showNextPhotoAnimated:YES];
}

You have 2 options, you can enable the app to be portrait + landscape and go through your VCs and add the 3 rotation methods, shouldAutorotate, preferredOrientation and presentationOrientation, OR, you on this specific VC you can register for NotificationCenter notifications for device orientation, and even though the phone orientation may be locked and / or the apps orientation locked you should get a notification of the rotation happening and apply your own animation transformation to make it appear landscape, this is how most camera apps seem to do it as far as I am aware, becuase you dont want a view port of the camera rotating.
NotificationCenter.default.addObserver(self, selector: Selector, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)

Related

iOS full screen camera overlay

I am new to objective-c and have been searching for an answer to this question for a while...
I am creating a photo-sharing app and I want the camera to be full-screen. I have used the following code to hide the default camera overlay and create my own, and make the camera full-screen. On the next screen, I want to display the image captured as full-screen again, but the image is getting collapsed sideways.
Setting the camera overlay:
-(void)loadCamera {
self.imagePicker = [[UIImagePickerController alloc]init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.delegate = self;
self.imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.imagePicker.showsCameraControls = NO;
self.overlayIV = [[WAUCameraOverlayView alloc]initWithFrame:self.imagePicker.cameraOverlayView.frame];
[self.imagePicker.cameraOverlayView addSubview:self.overlayIV];
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 71.0); //This slots the preview exactly in the middle of the screen by moving it down 71 points
self.imagePicker.cameraViewTransform = translate;
CGAffineTransform scale = CGAffineTransformScale(translate, 1.333333, 1.333333);
self.imagePicker.cameraViewTransform = scale;
[self presentViewController:self.imagePicker animated:YES completion:nil];
}
The above code works great and makes the camera full-screen with my custom overlay. Then, this block of code gets executed:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self.overlayIV removeFromSuperview];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
I pass "image" to the next screen and initialize it to the size of the screen, but it gets stretched... any way to save/display the image captured from the full-screen camera in the exact ratio and size?
EDIT: The code I use to display the image is:
UIImageView *capturedImageView =[[UIImageView alloc]initWithFrame:self.frame];
capturedImageView.image = aImage;
capturedImageView.contentMode = UIViewContentModeScaleAspectFill;
[self addSubview:capturedImageView];
I want the image to be the size of the screen, and the same ratio/aspect as it was captured in the camera

iOS return landscape orientation when is Portrait

I am trying to control iAd size when starts from landscape or portrait. Problem is that device tells that is on landscape when is on portrait! How to handle it? Thank you
- (void)viewDidLoad
{
//iAd
adView =[[ADBannerView alloc] initWithFrame:CGRectZero];
adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];
adView.delegate = self;
if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
[self.view addSubview:adView];
[super viewDidLoad];
}
You almost always want to use [self interfaceOrientation] here.
Regarding why orientation doesn't work, note the docs:
The value of this property always returns 0 unless orientation notifications have been enabled by calling beginGeneratingDeviceOrientationNotifications.
Are you sure it's telling you it's on landspace or simply not Portrait, as you if is setup to only recognize Portrait. It's possible that the simulator is returning nil, as mentioned in this thread: UIDevice currentDevice's "orientation" always null
Are you using the simulator or a device?

iPad: UIModalPresentationFormSheet fails on landscape mode

We've the next problem in our iPad version.
I've a NavigationController inside a UITabBar. I want to show a Form with a look&feel similar than the e-Mail form.
I use the same code to show a model centered:
// View to be displayed in the modal
AdhocViewController *controller = [[AdhocViewController alloc] initWithNibName:#"AdhocViewController" bundle:[NSBundle mainBundle]];
controller.caller = self;
// The form will need a navigation bar to cancel or save the form
UINavigationController *modalViewNavController = [[UINavigationController alloc]
initWithRootViewController:controller];
// Configurate the modal presentation and transition
modalViewNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
modalViewNavController.modalPresentationStyle = UIModalPresentationFormSheet;
// Show the new view
[self presentModalViewController:modalViewNavController animated:YES];
This code works perfectly on portrait mode, but on landscape the view appears partially out of the screen ... and I didn't found yet the way to solve it.
I test some of the solutions I found here ...
And try to add the next lines after preset the model view to resize it, but doesn't work it out
controller.view.superview.frame = CGRectMake(0, 0, 600, 700);
controller.view.superview.center = self.view.center;
Any suggestion?
Thanks,
Ivan
References in StackOverflow:
iPad modalPresentationStyle UIModalPresentationFormSheet orientation problem
UIModalPresentationFullScreen not working in iPad landscape mode?
UIModalPresentationFormSheet on iPad in landscape mode
How to resize a UIModalPresentationFormSheet?
With iOS7 the trick is to set the modalTransitionStyle to UIModalTransitionCrossDissolve.
UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:navigationController animated:YES completion:nil];
navigationController.view.superview.frame = CGRectMake(0, 0, 800, 544);
navigationController.view.superview.center = self.view.center;
https://coderwall.com/p/vebqaq
Finally the code was the next:
// Remove the modalTransitionStyle to enable the default behaviour and change to PageSheet
modalViewNavController.modalPresentationStyle = UIModalPresentationPageSheet;
// Present the modal view and adapt the center depending of the orientation
[self presentModalViewController:modalViewNavController animated:YES];
UIDeviceOrientation _orientation = [controller interfaceOrientation];
if (UIDeviceOrientationIsPortrait(_orientation)){
modalViewNavController.view.superview.center = CGPointMake(768/2, 1024/2 + 10);
} else {
modalViewNavController.view.superview.center = CGPointMake(768/2 - 10, 1024/2);
}
The +10 and -10 is because by deafult the NavigationController of the modal was out of the screen on top.
It is ... a crappy solution :SS but works ... Although if anybody have suggestions would be nice to know.
Seams that if I need to include the same center for both orientation, maybe the orientation of the superview is not the expected one.
In this solution, when I dissmiss the modal view on Portrait orientation, at least on the iPad simulator, it rotate to portrait mode automatically ...
The final solution was to execute the presentModalViewController over the main controller, the UITabBar, and update the dismiss method to be executed also over it.
[tabbar presentModalViewController:modalViewNavController animated:YES];
UIDeviceOrientation _orientation = [controller interfaceOrientation];
if (UIDeviceOrientationIsPortrait(_orientation)){
modalViewNavController.view.superview.center = CGPointMake(768/2, 1024/2 + 10);
} else {
modalViewNavController.view.superview.center = CGPointMake(1024/2, 768/2 + 10);
}
Finally!!!!
Thank you,
Iván
In iOS 7, to solve the problem of the modal view controller to appear to the left after apparition of the keyboard (problem that I have when I present an EKEventEditViewController in UIModalPresentationFormSheet, I do :
[self presentViewController:modalViewController animated:YES completion:^{
modalViewController.view.superview.center = self.view.center;
}];

Phonegap-ipad app -Adjust Launch image acc to Orientation

I am trying to explore ipad dev using phonegap. The problem that i have now is,
I have four different launch images for different orientations. When the app is launched, the correct launch image is being shown for a moment. After this,phonegap tries to load a imageview with default.png and displays it till webview is fully loaded. The problem lies here.. The imageview is autorotated based on the current orientation. So if the current orientation is LandscapeLeft, imageview tries to rotate default.png before displaying it Which is not i wanted and that is why i have different launch images.So in effect, you will have a landscapeleft.png and then the auto-rotated default.png before i get to see the webview.
So i tried changing the phonegapdelegate like this (in applicationDidFinishLaunching)
UIImage* image=nil;
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight ){
NSLog(#"In default5");
image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Default5" ofType:#"png"]];
}
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ){
NSLog(#"In default6");
image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Default6" ofType:#"png"]];
}
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown ){
NSLog(#"In default7");
image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Default7" ofType:#"png"]];
}
imageView = [[UIImageView alloc] initWithImage:image];
[image release];
It didn't work and upon debugging i found that the statusbarorientation is always portrait. That may be because phonegap tries to set portrait as the statusbarorientation in the same applicationDidFinishLaunching method(before loading this image view).
Can someone tell me how to load the image view with correct image?
USE THESE NAMES:
Default-LandscapeLeft-ipad.Png
Default-LandscapeRight-ipad.Png
Default-Portrait-ipad.Png
Default-PortraitUpsideDown-ipad.Png
More: http://www.weston-fl.com/blog/?p=840
applicationDidFinishLaunching is too early for the app to receive orientation change notifications from the os. Hence you cannot determine the orientation here.
So the best possible solution is to do it in a lifecycle stage which is capable of determining the current orientaion.In my case, webViewDidStartLoading

How to turn off UIWebView horizontal bounce

Simple problem, I have a webview that is supposed to hold just an image for the user to be able to zoom in and out. To keep my look clean, I want to completely disable bouncing on this view, but still allow scrolling. This solution does work for the vertical bounce, but as soon as I zoom the image to a size larger than the screen, horizontal bounce is still possible:
for (id subview in webView.subviews
{
if ( [[subview class] isSubclassOfClass:[UIScrollView class]] )
{
((UIScrollView*) subview).bounces = NO;
((UIScrollView*) subview).alwaysBounceVertical = NO;
((UIScrollView*) subview).alwaysBounceHorizontal = NO;
((UIScrollView*) subview).bouncesZoom = NO;
}
}
The following code did the trick for us to stop bouncing:
NSString* scriptToPreventBouncing = #"<script type=\"text/javascript\"> document.ontouchmove = function(e){ e.preventDefault(); } </script>";
NSString* footerHTML = #"<div>All rights reserved</div>";
[footer loadHTMLString: [scriptToPreventBouncing stringByAppendingString:footerHTML] baseURL:[NSURL URLWithString:#"http://somewebsite.com"]];
I am not sure if this will disable the zooming of image. But it should stop the bouncing.
On iOS 5 you can solve your problem this way:
UIWebView *webView = [[UIWebView alloc] ....];
webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
NOTE: this will work only on iOS5 and higher