presentViewController shows black sceen while UIModalTransitionStyleFlipHorizontal objective c - 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];

Related

Add button horizontally to Page Control

I need to add a button horizontally to a Page Control in UIPageViewController. I have added my pageviewcontroller as a subview to a ViewController, by default im getting the page control .Now I wanted to add a button, Can anyone suggest any way to add button ?
Thanks in advance!!
_pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
self.view.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
#"Main" bundle:[NSBundle mainBundle]];
UIViewController *p1 = [storyboard instantiateViewControllerWithIdentifier:#"First"];
UIViewController *p2 = [storyboard
instantiateViewControllerWithIdentifier:#"Second"];
UIViewController *p3 = [storyboard
instantiateViewControllerWithIdentifier:#"Third"];
UIViewController *p4 = [storyboard
instantiateViewControllerWithIdentifier:#"Fourth"];
_Array = #[p1,p2,p3,p4];
_pageViewController.dataSource = self;
_pageViewController.delegate = self;
[_pageViewController setViewControllers:#[_Array[0]]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
[_pageViewController willMoveToParentViewController:self];
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.view sendSubviewToBack:self.pageViewController.view];
[_pageViewController didMoveToParentViewController:self];
I believe this is what youre looking for. He explains in detail how to add the buttons "on top of " your page view controller view. You can do this after you add the page view controller, you can use the sendSubviewToBack method to ensure that the buttons remain in the foreground while you will be able to swipe between the different view controllers of your page view controller. Have a look here
you can extract the view where page control is kept on, then you can do what ever you want. Below is the code for extracing the pagecontrol view:
NSArray *subviews = self.pageController.view.subviews;
for (int i=0; i<[subviews count]; i++) {
if ([[subviews objectAtIndex:i] isKindOfClass:[UIPageControl class]]) {
self.pageControl = (UIPageControl *)[subviews objectAtIndex:i];
}
}
UIView *pageControlBaseView = [[UIView alloc] initWithFrame:CGRectMake(0,60,100, 40)];
[pageControlBaseView addSubview:self.pageControl];
self.pageControl.pageIndicatorTintColor = [UIColor redcolor];
self.pageControl.currentPageIndicatorTintColor = [UIColor greencolor];
[self.view addSubview:pageControlBaseView];
please let me know if you need more clarity.

Objective-C Modal View Controller with Transparent Background

I wanted to create a modal View Controller that would have a transparent background but when I tried setting the alpha of the background to 0.5 it just made the view behind it completely black. This is because the background views are being removed after the transition.
self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
[self setModalPresentationStyle:UIModalPresentationFullScreen];
[self setDefinesPresentationContext:YES];
Then presenting View Controller Code
SecondViewController *alertView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self presentViewController:alertView animated:YES completion:nil];
please look at the link
image/linke.gif
Try this code in the action of the button in the firstViewController to change the view controller and present a new class secondViewController
secondViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:#"secondViewController"];
VC.view.backgroundColor=[UIColor colorWithWhite:0 alpha:0.1f];
VC.modalPresentationStyle=UIModalPresentationOverCurrentContext;
[self presentViewController:VC animated:NO completion:nil];

Modifying UINavigation controller programatically in Xcode5

I have a programmatically generated UINavigationController applied to each of my ViewControllers but this UINavigationController is blank. I need to add some text, an image (if possible) and two buttons.
I have managed to do something similar with a very basic app that only has one ViewController and UINavigationController created in the normal manner but do not know what to do in regards to a programmatically generated one.
I am using storyboards in XCode5/iOS7.
Here is the code that generates the UINavigationController and launches the first ViewController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
MainViewController* mainVC = [mainStoryboard instantiateInitialViewController];
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:mainVC];
[self.window setRootViewController:navVC];
[_window makeKeyAndVisible];
return YES;
}
I have tried things that I thought would be obvious like:
navVC.navigationBar.backgroundColor = [UIColor redColor];
To change the colour or:
[navVC setTitle:#"Test title"];
But nothing changes, the only way I could get the title to change was to change the title of mainVC
[mainVC setTitle:#"Test title"];
Changing the title in the MainViewController.m file itself does nothing.
So how do I modify the UINavigationController (navVC)?
Thanks,
You should be able to set an image to your navigation bar in this way:
UINavigationBar *navBar = navVC.navigationBar;
UIImage *image = [UIImage imageNamed:#"YourNavBarImg.png"];
[navBar setBackgroundImage:image];
and this to change the nav bar tint color:
[navVC.navigationBar setTranslucent:NO];
[navVC.navigationBar setBarTintColor:[UIColor redColor]];
about buttons (UIBarButtonItem) into nav bar:
// where "self" is your current viewcontroller
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:button1,button2, nil];

exit from TabBarController to ViewController

I have 2 viewcontrollers in a TabBarController, in 2nd ViewController I have a button which on click should take me to ThanksViewController with out Tabs anymore!!
Please check my code below:
//AppDelegate.m
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:_viewController];
self.window.rootViewController = nav;
//ViewController.m
tab=[[UITabBarController alloc]init];
tab.delegate=self;
oneViewController=[[OneViewController alloc]init];
UINavigationController *oneNav=[[UINavigationController alloc]initWithRootViewController:oneViewController];
oneNav.title=#"One";
twoViewController=[[TwoViewController alloc]init];
UINavigationController *twoNav=[[UINavigationController alloc]initWithRootViewController:twoViewController];
twoNav.title=#"Two";
views=[[NSMutableArray alloc]initWithObjects:oneNav, twoNav, nil];
tab.viewControllers=views;
[tab.view setFrame:CGRectMake(0, 0, 1024, 748)];
[self.view addSubview:tab.view];
In my TwoViewController (tab 2) I've a Button 'OK' which on click should take me to ThanksViewController, for that I've written the following code:
//TwoViewController.m
-(void)OK
{
ThanksViewController *thanksViewController=[[ThanksViewController alloc]init];
[self.navigationController pushViewController:thanksViewController animated:YES];
}
My problem is I want to exit from TabBarController and move on to the ThanksViewController(without TabBarController at the bottom) but in this case I'm getting the ThanksViewController in the TabBarController itself in place of the TwoViewController.
Can someone please suggest me in this case, thanks in advance.
After push ThanksViewController do you want to be possible to go back and present TabBarController again?
If so, use modal, like this:
ThanksViewController *view = [[ThanksViewController alloc] init];
UINavigationController *navThanks = [[UINavigationController alloc] initWithRootViewController:view];
[navThanks setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:navThanks animated:YES];
[self.view setHidden:YES];

Touch on ImageView to another ViewController

I have 2 ViewControllers and I create one UIImageView to show like Splash Screen on IPhone. I write it in TestAppDelegate.m :
====================
splashScreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashScreen.image = [UIImage imageNamed:#"Default.png"];
[self.window addSubview:splashScreen];
sleep(6);
[splashScreen removeFromSuperview];
====================
My question is,
if I touch on this imageview I will go to 2nd ViewController.
else after time sleep, automatically to 1st ViewController.
So, it's possible to do that ?
Do this:
Add UIGestureRecognizerDelegate in appDelegate.h file.
#interface AppDelegate : UIResponder <UIApplicationDelegate,UIGestureRecognizerDelegate>
Now
splashScreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashScreen.userInteractionEnabled = YES;
splashScreen.image = [UIImage imageNamed:#"Default.png"];
UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 1;
tapRecognizer.delegate = self;
[splashScreen addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
[self.window addSubview:splashScreen];
sleep(6);
[splashScreen removeFromSuperview];
//add ViewController1 here
ViewController1 *objViewController1 = [[ViewController1 alloc]initWithNibName:#"ViewController1" bundle:nil];
[self.window addSubview:objViewController1.view];
Now handler will be called when tapped on splash screen
- (void)handleTap:(UITapGestureRecognizer*)recognizer
{
// Do Your thing.
if (recognizer.state == UIGestureRecognizerStateEnded)
{
[splashScreen removeFromSuperview]; //edited here
ViewController2 *objViewController2 = [[ViewController2 alloc]initWithNibName:#"ViewController2" bundle:nil];
[self.window addSubview:objViewController2.view];
}
}
Yes. It's possible.In AppDelegate keep NSTimer.
In the selector of timer write code to push to the 1st view controller.
And put a Touch Recognizer on the imageview and on the touch event write code to push to the 2nd View Controller.