MFMessageComposeViewController not properly displayed - objective-c

I'm using MFMessageComposeViewController in order to show the SMS send interface.
My app uses full screen, the status bar is hidden by settings in plist file (Status bar is initially hidden = YES).
When I show the message composer with:
+(void)composeSMS:(id)sender
{
if (![MFMessageComposeViewController canSendText]) return;
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.wantsFullScreenLayout = YES;
controller.messageComposeDelegate = sender;
[controller setBody:#"He descubierto un App estupenda! . "];
[controller setModalPresentationStyle:UIModalTransitionStyleFlipHorizontal];
if (controller) [sender presentModalViewController:controller animated:YES];
[controller release];
}
The problem is when the composer is displayed the navigation bar is on the top y = 0, but between this bar and the rest of outlets of the view appears an empty space of the same size as the status bar. The status bar is showed in this screen (second issue) but is overlapping the navigation bar of the composer view.
In other projects where the status bar is not hidden, this works like a charm. But this is the first project where it is used without status bar and this is happening.
Anyone knows how to fix it?
Thanks.

Hide the status bar after you modal presented the message controller. Something like this:
controller.wantsFullScreenLayout = NO;
[self presentModalViewController:controller animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];

The way I dealt with using iMessage inside an app was to take control of the status bar myself.
For example:
[[UIApplication sharedApplication] setStatusBarHidden:FALSE withAnimation:UIStatusBarAnimationSlide];
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:TRUE];
[controller release];
Then when finished either through a send or a cancel:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
[self dismissModalViewControllerAnimated:TRUE];
[[UIApplication sharedApplication] setStatusBarHidden:TRUE withAnimation:UIStatusBarAnimationSlide];
self.view.frame = CGRectMake(0.0, 0.0, [LayoutHelper width], [LayoutHelper height]);
self.view.center = CGPointMake([LayoutHelper xCenterPoint], [LayoutHelper yCenterPoint]-20);
}
This seems to display the iMessage and then return to the app without any empty space appearing from the status bar being added or removed.
This is my first post so i hope this helps somehow.
cheers

Related

presentViewController shows black sceen while UIModalTransitionStyleFlipHorizontal objective c

I'm facing issue with the UIModalTransitionStyleFlipHorizontal, Which gives black screen at background while transition and shows the actual screen.
After first time it shows the last view which added as rootview.
What actually I need to achieve is I don want to show the black and previous screen. It should show an empty screen background as like the below image.
The code I used to achieve the transition is
- (void)popViewController {
UIViewController* rootController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"MainViewController"];
rootController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:rootController];
[self.window.rootViewController presentViewController:navigation animated:YES completion:nil];
[self.window makeKeyAndVisible];
}
I'm using storyboard with dynamic rootview.Anybody help me to fix it out.
Thanks
Remove subview
Add this code on your method popViewController
AppDelegate *appDelegate =(AppDelegate *)[[UIApplication sharedApplication]delegate];
NSArray *subViewArray = [appDelegate.window subviews];
for (id obj in subViewArray)
{
[obj removeFromSuperview];
}
I solved the issue by add window subview with background.
UIImageView* background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height)];
background.image = [UIImage imageNamed:#"TermsBg"];
[self.window addSubview:background];

Statusbar overlapping on UIImagepickercontroller's Camera View in iOS 7 and iOS 8

im using UIImagepickercontroller to take photo and choose existing photos, when the camera view appears, the top portion on camera was covered by the white status bar. How can i remove the status bar or hide the status bar. Many of them saying its a ios 7 bug, it has been fixed in ios 7.1, but still i'm facing this problem.
This is my code to show the imagepickerController
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = (id)self;
imagePicker.sourceType = (buttonIndex == actionSheet.firstOtherButtonIndex ?
UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypePhotoLibrary);
[self.viewController presentViewController:imagePicker animated:YES completion:nil];
Also i tried by with below codes to hide statusbar
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
This
-(BOOL) prefersStatusBarHidden {
return YES;
}
And This in Delegate
[UIApplication ShareApplication]SetStatusbarHidden:YES];
Right now i'm working with ios8, and this behaviour happening in all ios version.
Please help me out.
Actually the problem is in my rootviewcontroller i'm creating a Statusbar using UIView and setting its constraints for landscape and portrait programmatically
- (void)setTopBar {
if(topBar == nil && [[UIApplication sharedApplication] keyWindow] != nil) {
topBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
topBar.backgroundColor = navController.view.backgroundColor;
topBar.tag = topBarViewTag;
UIView *containerView = [[UIApplication sharedApplication] keyWindow];
[containerView addSubview:topBar];
[containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[view(20)]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:#{#"view" : topBar}]];
[containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"|[view]|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:#{#"view" : topBar}]];
[containerView layoutSubviews];
}
}
so when i commented the above method in ViewwillAppear, status bar where not showing up, so the problem is with my code.
if anyone face the same issue, i suggest you to have a look on your RootViewcontroller, which acts a navigation to all other classes.

UIImagepickerController is not showing camera in full view for iPhone 4.2

When I invoke camera using the UIimagepicker controller it does not show in full screen mode on iPhone with iOS version 4.2, but it does work in iOS 5.
Can anyone tell me the code that needs to be changed and what is the problem with existing code?
I am using the following code:
- (IBAction)takePicture:(id)sender
{
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.allowsEditing = NO;
imagePicker.toolbarHidden = YES;
imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
imagePicker.wantsFullScreenLayout = YES;
if ([UIImagePickerController respondsToSelector:#selector(isCameraDeviceAvailable:)])
{
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])
{
[imagePicker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
}
}
// Show the camera UI and View Finder.
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
Please check the attachment
Image is here
one of the solution is applying scaling trasnformation - here on stack maybe it will help
I don't see why you are doing these 3 things:
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[self.camPicker.view setUserInteractionEnabled:YES];
Or for that matter why you are caching the instance of UIImagePickerController (this may cause significantly higher idle memory usage for your application compared to discarding the image picker controller between uses).
Does it work better if you don't do these things?

Disappearing status bar at the top after MPMoviePlayerController is closed

Having an interesting little problem with my iPhone app. I have a view with a table and each cell, when clicked, plays a video fullscreen then when you press done, the video stops and goes back to the table view. The only problem is, when you press done within the first 2 or 3 seconds of the video loading, when the view goes back to the table view, the bar at the top of the screen that tells the time and battery strength etc is no longer there, its just a white space. But if you press done after the first few seconds, then when you go back to the table view, everything is absolutely fine! I have absolutely no idea why this is happening and the only thing I found on the internet is this which is some guy with pretty much exactly the same problem as me:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/53020-disappearing-status-bar.html
This lead me to try using:
[UIApplication sharedApplication].statusBarHidden = NO;
However this lead nowhere either.
The code that is executed when they click on a video:
NSString *path = [[NSBundle mainBundle] pathForResource:currentTitle ofType:#"m4v"];
NSURL *url = [NSURL fileURLWithPath:path];
movieController = [[MPMoviePlayerController alloc] initWithContentURL:url];
[movieController setControlStyle:MPMovieControlStyleFullscreen];
[movieController setFullscreen:YES];
movieController.view.frame = self.view.bounds;
[self.view addSubview:movieController.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
And the code that executes either when the video is done or when the user clicks done is:
NSLog(#"movieController moviePlayBackDidFinish");
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[movieController setFullscreen:NO animated:NO];
[movieController.view removeFromSuperview];
[movieController release];
LiveEventsView *liveEventsView = [[LiveEventsView alloc] initWithNibName:#"LiveEventsView" bundle:nil];
UIView *currentView = self.view;
UIView *theWindow = [currentView superview];
UIView *newView = liveEventsView.view;
newView.frame = CGRectMake(0, 20, 320, 460);
[currentView removeFromSuperview];
[theWindow addSubview:newView];
[UIApplication sharedApplication].statusBarHidden = NO;
If anybody can shed any light on this situation, I would be very grateful as it is extremely frustrating!
Thanks,
Matt
Maybe the animation from when the video view disappears is causing a timing issue with the status bar animation.
try delaying the statusBarHidden = NO call by a few seconds.
NSInteger delay = 3;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
[UIApplication sharedApplication].statusBarHidden = NO;
});
You can just set the delay to be a float instead. So it would be
float delay = 0.1;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
[UIApplication sharedApplication].statusBarHidden = NO;
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
});
I had the same problem and solved it by modifying richerd's code a bit. 0.1 second is acceptable imo. I also had to change the status bar style since it returned a BlackTranslucent bar style and the original was BlackOpaque style. But works fine now.
I've found that with the given solutions the content often disappears beneath the status bar. This approach fixes it.
Register for MPMoviePlayerWillExitFullscreenNotification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerWillExitFullscreen:)
name:MPMoviePlayerWillExitFullscreenNotification
object:self.moviePlayer];
And then reset the status bar visibility AND remove and re-add the rootViewController from the main window, this will make sure that the bounds of the view are correct again.
- (void)moviePlayerWillExitFullscreen:(NSNotification *)notification {
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
id rootViewController = appDelegate.window.rootViewController;
appDelegate.window.rootViewController = nil;
appDelegate.window.rootViewController = rootViewController;
}

ModalViewController loading on top of another Modal

There may be a better way to do this, and please direct me if there is.
I'm creating an UIImagePickerController with an overlayView in viewDidAppear for 'choose from library', 'take photo', 'flash' 'camera source', etc.
// Set up the camera
imagePicker = [[UIImagePickerController alloc]
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.cameraOverlayView = [self cameraOverlayView];
cameraOverlayView.backgroundColor = [UIColor clearColor];
imagePicker.showsCameraControls = NO;
imagePicker.toolbarHidden = YES;
imagePicker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:imagePicker animated:YES];
I then have an IBAction that calls my 'choose from library function', loading another UIImagePickerController to choose a photo from the device.
- (IBAction)library:(id)sender
{
UIImagePickerController *libraryPicker = [[[UIImagePickerController alloc] init] autorelease];
libraryPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
libraryPicker.delegate = self;
[self.imagePicker presentModalViewController:libraryPicker animated:YES];
}
I'm getting a white bar across the top about the size of a status bar when the 'choose from library' modal is presented. I know it has something to do with overlaying a modal on top of a modal, but I don't know how to solve it. (IE, my view layout for 'take photo' navigates fine, although doesn't display the additional 'choose from library' modal).
Any ideas? Any help or direction would be greatly appreciated!
Try
[self presentModalViewController:libraryPicker animated:YES];
Instead of
[self.imagePicker presentModalViewController:libraryPicker animated:YES];