Translucent Viewcontroller over another Viewcontroller with different Orientation behaviour - objective-c

For an app targeted at both iOS 7 and iOS 8, I'm using two ViewControllers which should have the following characteristics:
ViewController 1 (VC1) is in Portrait Mode
VC1 created ViewController 2 (VC2) which is in Landscape mode
VC2 has a translucent background so that VC1's contents are visible
I've referred to IOS 7: Transparent Viewcontroller Background over another Viewcontroller with different Orientation behaviour but the solution provided does not work. On iOS 8, I can either get landscape orientation or transparency for VC2 but not both
Here's what I'm doing:
self.view.backgroundColor = [UIColor clearColor];
UILabel* label = [[UILabel alloc] initWithFrame:self.view.frame];
label.text = #" I'M VC1";
[self.view addSubview:label];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
LandscapeViewController* lvc = [[LandscapeViewController alloc] init];
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
//Uncomment this line for transparency but loses orientation
//lvc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:lvc animated:YES completion:nil];
});
Any idea what's wrong and how can I make it work?

Related

Objective-C: Status bar color and navigation color is not being same even I set same color in iOS 11

Sorry for Lengthy description-
On which Application I am working, it is 2 years old. As we wanted to give support for iOS 11. On particular view controller, we needed to rotate the screen with 180degree.
For this we used-
[[[UIApplication sharedApplication] delegate] window].transform = CGAffineTransformMakeRotation(M_PI);
By this way we actually transform the window.
It was working fine before iOS11.0. In iOS 11 when we again transform to original view then there is the problem with the status bar.
So, to resolving this issue I am changing the color of Navigation Bar as well as Status Bar,
#import "UINavigationController+Utilities.h"
#implementation UINavigationController (Utilities)
UIView *view;
-(void)setStatusBackground:(UIColor *)color
{
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"11.0"))
{
if (view == nil) {
view = [[UIView alloc] initWithFrame: CGRectMake(0, 0, DEVICE_SCREEN_WIDTH, 20)] ;
view.backgroundColor = color;
[self.view addSubview:view];
}
view.backgroundColor = color;
}
}
#end
Change background color of the navigation bar to Blue.
[self.navigationController.navigationBar setBarTintColor: HCCOLOR_BLUE];
[self.navigationController setStatusBackground:HCCOLOR_BLUE];
but the color is not same both. It looks little different.
I am adding the image-
This could be because might be your navigation bar is translucent
Try self.navigationController.navigationBar.translucent = NO;

StatusBar background color in iOS7

Im working on a app compatible from ios6 onwards. in iOS 7 status bar is overlapping views and navigationbar. i want status bar in iOS 6 style. like it should appear above all UI objects, views,Viewcontroller and navigation controller. how can we achieve this?
For fixing the overlapping issue just try this link Status bar and navigation bar issue in IOS7
and for using status bar style similar to ios 6 this link may help you Change StatusBar style
In your app delegate's applicationDidFinishLaunching method:
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];
Set UIStatusBarStyleBlackTranslucent/UIStatusBarStyleBlackOpaque for getting status bar similar to iOS6.
Hope this may help you
I am late for this Answer, but i just want to share what i did, which is basically
the easiest solution
First of all-> Go to your info.plist File and add Status Bar Style->Transparent Black Style(Alpha of 0.5)
Now ,here it Goes:-
Add this code in your AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Whatever your code goes here
if(kDeviceiPad){
//adding status bar for IOS7 ipad
if (IS_IOS7) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 1024, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
}
}
else{
//adding status bar for IOS7 iphone
if (IS_IOS7) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //You can give your own color pattern
[self.window.rootViewController.view addSubview:addStatusBar];
}
return YES;
}

How to show a "Loading..." gif image above the Splash image in objective c?

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.

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;
}];

Present formsheet modal ViewController using horizontal flip

I currently show a modal UIViewController in the formSheet style that was presented with the coverVertical animation. I am trying to present another modal UIViewController from it, using currentContext for the presentation style and flipHorizontal for the animation style. It does work, but there is a solid white white background behind the flip as it occurs. Any advice on how to successfully present another formsheet modal UIViewController using the flipHorizontal style from a pre-existing modal UIViewController in the formSheet style would be appreciated please! Thanks
Code:
// Loading of first modalVC
- (void)showModalVC {
Modal1VC *modal1VC = [[Modal1VC alloc] init];
modal1VC.modalPresentationStyle = UIModalPresentationFormSheet;
modal1VC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:modal1VC animated:YES];
[modal1VC release];
modal1VC.view.superview.bounds = CGRectMake(0, 0, 400, 400);
}
// Loading of second modalVC in Modal1VC
- (void)buttonTapped:(id)sender {
UIViewController *modal2VC = [[UIViewController alloc] init];
modal2VC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
modal2VC.modalPresentationStyle = UIModalPresentationCurrentContext;
modal2VC.view.backgroundColor = [UIColor greenColor];
[self presentModalViewController:modal2VC animated:YES];
[modal2VC release];
modal2VC.view.superview.bounds = CGRectMake(0, 0, 400, 400);
}
UIViewController *presentingViewController = //allocate your VC
[modalViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
UIViewController *modalViewController = //your modal VC
[presentingViewController presentModalViewController:modalViewController animated:YES];
This is all the code you need ;)
It sounds like your transition is working, but the white background shown on the flip transition is the problem?
During the flip transition, the white background that is shown is actually the window. You can change the color that is shown by setting the backgroundColor property of window in the AppDelegate.
That would seem to be a limitation of presentModalViewController:animated:.
Instead of [self presentModalViewController:modal2VC animated:YES], you may be able to get the effect you want using UIView animations. Perhaps something like this:
[UIView transitionWithView:self.view.window
duration:0.3
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[self presentModalViewController:modal2VC animated:NO];
} completion:NULL];