I am having a native app, in which I have to show Share feature with UIActivityViewController. My app needs to support both orientations. When the share pops up and I change the device orientation, then the orientation for popup changes but the background screen remains its orientation and when I cancel it out then the background screen looks messy.
Please let me know how to fix this as my app is in release phase and I am stuck with this issue.
NSString *textToShare = #"your text";
NSArray *itemsToShare = #[textToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[activityVC setCompletionHandler:^(NSString *activityType, BOOL completed){
IsAppLoadedFirstTime=false;
[infoImageabc1 removeFromSuperview];
[InfoLabel1 removeFromSuperview];
[ InfoLabel2 removeFromSuperview];
[InfoShare removeFromSuperview];
[self loadView];
}];
[self presentViewController:activityVC animated:YES completion:nil];
I can change the orientation as soon as the activity popup closes, but before the (when the popup is opened), then the UI is not in proper orientation say if after opening the popup I changed the orientation to Portrait, then my UI remains in Landscape mode, but as it includes text also, so UI looks bad.
Related
I'm not great at creating views in code yet so this is probably a simple question.
In my iPad app I have this image picker and I would like to present it in a 500x500 modal view centred on screen OR in a formsheet centre-screen:
_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.delegate = self;
_imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
_imagePicker.allowsEditing = NO;
_imagePicker.navigationBar.tintColor = [UIColor redColor];
_imagePicker.navigationBar.backgroundColor = [UIColor greenColor];
Now what do I do to both create the modal view or formsheet and present the image picker inside it?
(I've looked through many examples and Q&A and just can't find a simple answer. Thanks for your help!)
Form sheet is a modal presentation type. You change that by modifying the modalPresentationStyle property of a view controller before presentation.
_imagePicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:_imagePicker animated:YES completion:nil];
However, if you read the documentation of UIImagePickerController, you will see that Apple requires you to present the view controller inside a popover.
So:
if([_popoverController popoverVisible])
{
[_popoverController dismissPopoverAnimated:NO];
_popoverController = nil;
}
_popoverController = [[UIPopoverController alloc] initWithContentViewController:_imagePicker];
[_popoverController setDelegate:self];
[_popoverController presentPopoverFromBarButtonItem:_button permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
I want to show a GIF image over the splash-screen while the app is loading its data.
I have splash image that is showing for at least about 3 or 4 seconds which is why I want to show loading text, like a gif image, over the splash image so that users think that app is loading.
just add one label to your splash image and an NSTimer which change it's text periodically just as below
splash = [[UIImageView alloc] initWithFrame:self.window.frame];
splash.image = [UIImage imageNamed:#"splash"];
[self.window addSubview:splash];
this is the code i use to show my splash screen and then
NSTimer *loading = [[NSTimer alloc]init];
[loading performSelector:#selector(YOUR_SELECTOR) withObject:YOUR_LABEL afterDelay:0.3f];
where YOUR_SELECTOR is method in which you set the label text and YOUR_LABEL is label for which you set the text
EDIT
sorry for NSTimer actually i used activityindicator with text loading...
in application:didFinishLaunchingWithOptions: method
the code for it is
splash = [[UIImageView alloc] initWithFrame:self.window.frame];
splash.image = [UIImage imageNamed:#"splash"];
[self.window addSubview:splash];
hud = [[MBProgressHUD alloc]initWithView:splash];
[splash addSubview:hud];
hud.labelText = #"Loading...";
[hud show:YES];
[self performSelector:#selector(Load_FirstView) withObject:nil afterDelay:3];
[self.window makeKeyAndVisible];
and Load_FirstView method is as follow
-(void)Load_FirstView
{
[splash removeFromSuperview];
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
masterViewController.managedObjectContext = self.managedObjectContext;
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
}
If you are using the Default.png as a splash image, then there is no way to animate that. One way would be to launch the app quicker, only to then show an animated view for the duration of loading the data. So basically your only solution would be to move away from Default.png and use a custom view instead that can be animated.
Start off by using the Default.png and then load a UIView that contains a single UIImageView with the same frame as the UIView (entire screen). Set the Default.png as the UIImage of the ImageView and add whatever controls (such as the UIActivityIndicatorView) as you need.
In my phonegap-based iPhone web-app I implemented a plugin that uses AVCaptureVideoPreviewLayer to take a photo. To do so, when the plugins' startCamera method is called, I set the background of the webview to be transparent and insert the video capture layer below the layer of the webview. This works as expected (most of the time).
But for some strange reason, when I execute startCamera for the first time (after a fresh app start), the video layer isn't visible. Instead, the webview displays a white background, although the background color is set to clearColor. For all subsequent executions, the video layer is visible.
This is what I'm doing to show the camera:
AVCaptureSession * session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetHigh;
AVCaptureVideoPreviewLayer * videoLayer =
[[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
videoLayer.frame = self.webView.bounds;
CALayer *webViewLayer = self.webView.layer;
[webViewLayer.superlayer insertSublayer:videoLayer below:webViewLayer];
// ... session setup excluded
[session startRunning];
[self.webView setBackgroundColor:[UIColor clearColor]];
[self.webView setOpaque:NO];
In stopCamera() I do the following:
if (session) {
[session stopRunning];
}
[self.webView setBackgroundColor:[UIColor blackColor]];
[self.webView setOpaque:NO];
if (videoLayer != nil) {
[videoLayer removeFromSuperlayer];
}
Any ideas why the camera layer isn't visible for the first time?
Solved it: The problem was, that setting the opacity flag of the webview to NO didn't have any effect when it was done in startCamera(). To fix it, I set the opacity of the webview earlier - just when it was created. A webview with no opacity doesn't mean that it is transparent though - you also need to set the background color to [UIColor clearColor] (this is what is done in startCamera(); in stopCamera() the background color is set back to [UIColor blackColor]).
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;
}];
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