Why is view of UINavigationController root controller smaller than nav controller - ios

I am trying to create a transparent UINavigationBar and here is what I do:
First, I have a navVC and a general VC as root VC in my code.
SNLoginViewController *loginVC = [[SNLoginViewController alloc] init];
SNLoginNavController *loginNavVC = [[SNLoginNavController alloc] initWithRootViewController:loginVC];
[self presentViewController:loginNavVC animated:YES completion:nil];
I didn't override the init method of SNLoginViewController.
And here is the implementation of initWithRootViewController::
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController {
self = [super initWithRootViewController:rootViewController];
if (self) {
UIImage *bgImage = [UIImage imageNamed:#"bg"];
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage];
bgImageView.frame = [UIScreen mainScreen].bounds;
[self.view insertSubview:bgImageView atIndex:0];
[self.navigationBar setBackgroundImage:[UIImage imageNamed:#"transparent"]//transparent is a transparent png
forBarMetrics:UIBarMetricsCompact];
self.navigationBar.shadowImage = [UIImage imageNamed:#"transparent"];
self.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName: [UIFont systemFontOfSize:18]}];
self.navigationBar.clipsToBounds = YES;
}
return self;
}
Using these codes (setBackgroundImage:forBarMetrics:) I should have been able to make the navigation bar transparent but something went wrong. The major problem is that somehow the frame of loginVC is smaller than loginNavVC.
(source: zybuluo.com)
In the figure above the selected view is of loginVC and the one on the left is of loginNavVc. loginVC is smaller than loginNavVc.
But in viewDidLoad of loginVC I print the selected view, its frame is (0 0; 320 568) but when I print its description in view hierarchy (same address in memory), its frame is (0 64; 320 504). Why would this happen? How to make it full screen(not full screen like games, status bar should still be visiable)?

Add this before presenting your navigation controller.
[self.loginNavVC.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self. loginNavVC.navigationBar.translucent = YES;

Related

UINavigationBar leftBarButtonItem position

I have an iOS project with UINavigationController.
When I pushviewcontroller with
animated = YES
[self.navigationController pushViewController:viewController animated:YES];
the top leftbarbuttonitem (with image) is well positioned.
But if I set pushviewcontroller with
animated = NO
[self.navigationController pushViewController:viewController animated:NO];
the top leftbarbuttonitem (with image) is not positioned exactly the same place with previous one. Does anyone have any idea?
SAMPLE CODE
- (void)addBackButtonWithoutAnimation {
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
UIImage *closeImage = [UIImage imageNamed:#"icon_back"];
UIBarButtonItem *closeBackButton = [[UIBarButtonItem alloc] initWithImage:closeImage style:UIBarButtonItemStylePlain target:self action:#selector(closeBackButtonwithoutAnimationDidClick)];
self.navigationItem.leftBarButtonItem = closeBackButton;
self.navigationItem.hidesBackButton = YES;}

Present view controller before initial view controller is shown

I have an app that has the following structure:
The main view controller is a tab bar view controller that has 4 tabs.
Users can only access these view controllers when they are logged in. When app launches, it loads it's initial view controller (the tab bar one), and then I check to see if user is authenticated. If it's not, I present a login view controller.
The problem I'm having is that when app launches, it's loading the tab bar controller and from that controller it presents the login view controller, but it does so with a small time window that shows the tab bar controller's view on the screen, before the login's view. I need to directly present the login view, from the tab bar controller, but without showing tab bar controller's view in that small time interval, as it's not user friendly.
I read some answers on stackoverflow about presenting the new view controller without animation, and that's what I'm doing, but the problem persists.
I hope I've been clear enough on the issue, if you need more information just let me know.
EDIT: I'm presenting the login view controller on applicationDidBecomeActive: on applicationDelegate.m
In app delegate, In didFinishLaunchingWithOptions,
In condition if login or not,
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *viewController =[storyboard instantiateViewControllerWithIdentifier:#"your identifier"];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
You should something like this when you have view controller in storyboard.
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
FirstViewController *firstviewController = [storyboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
SecondViewController *secondviewController = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
firstviewController.tabBarItem.image = [UIImage imageNamed:#"24-around-7"];
firstviewController.tabBarItem.title = #"First";
secondviewController.tabBarItem.title = #"Second";
secondviewController.tabBarItem.image = [UIImage imageNamed:#"60-around-7"];
UITabBarController *tabBarController = [[UITabBarController alloc]init];
tabBarController.viewControllers = #[firstviewController,secondviewController];
self.window.rootViewController = tabBarController;
And in FirstViewController's viewDidAppear you should check for user logged in or not and present view controller.
BOOL loginStatus = [[NSUserDefaults standardUserDefaults] boolForKey:#"isLoggedIn"];
if(loginStatus == NO){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
LoginViewController *loginViewcontroller = [storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
[self presentViewController:loginViewcontroller animated:YES completion:nil];
}
After successful login just dismiss login view controller . If user logout just present the loginviewcontroller
CREATE NEW .H .M
(this is my code)
yourController.h and yourController.m
then open
yourcontroller.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSLog(#"initWithFrame");
[self setupPinPopUp];
}
return self;
}
-(void)setupPinPopUp{
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurEffectView.frame = CGRectMake(0, 66, kSCREEN_WIDTH, kSCREEN_HEIGHT-66);
blurEffectView.userInteractionEnabled = TRUE;
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(handleSingleTap:)];
[blurEffectView addGestureRecognizer:singleFingerTap];
blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:blurEffectView];
UIView *popUpMainView = [[UIView alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH/2-150, kSCREEN_HEIGHT/2-160, 300, 270)];
popUpMainView.backgroundColor = Clear;
[self addSubview:popUpMainView];
UIView *popUpInsideView = [[UIView alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH/2-150, kSCREEN_HEIGHT/2-102, 300, 210)];
popUpInsideView.backgroundColor = White;
popUpInsideView.layer.cornerRadius = 2.0;
popUpInsideView.clipsToBounds = TRUE;
[self addSubview:popUpInsideView];
UIImageView *imgCircleView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 0, 100, 100)];
imgCircleView.layer.cornerRadius = 50;
imgCircleView.backgroundColor = White;
imgCircleView.clipsToBounds = TRUE;
[popUpMainView addSubview:imgCircleView];
UIImageView *imgInnerCircleView = [[UIImageView alloc]initWithFrame:CGRectMake(25, 8, 50, 50)];
imgInnerCircleView.backgroundColor = Clear;
imgInnerCircleView.image = [UIImage imageNamed:#"support"];
[imgCircleView addSubview:imgInnerCircleView];
UILabel *lblHeading = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, popUpMainView.frame.size.width, 45)];
lblHeading.text = #"CUSTOMER SUPPORT";
lblHeading.numberOfLines = 0;
lblHeading.textColor = Black;
lblHeading.textAlignment = NSTextAlignmentCenter;
lblHeading.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:21];
[popUpInsideView addSubview:lblHeading];
UIButton *btnPhoneNumber = [[UIButton alloc]initWithFrame:CGRectMake(0, lblHeading.frame.size.height+lblHeading.frame.origin.y+10, popUpMainView.frame.size.width, 45)];
[btnPhoneNumber setTitle:#"18002345678" forState:UIControlStateNormal];
[btnPhoneNumber setTitleColor:Black forState:UIControlStateNormal];
btnPhoneNumber.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
btnPhoneNumber.titleLabel.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:18];
[btnPhoneNumber addTarget:self action:#selector(callSupport:) forControlEvents:UIControlEventTouchUpInside];
[popUpInsideView addSubview:btnPhoneNumber];
UIButton *btnEmail = [[UIButton alloc]initWithFrame:CGRectMake(0, btnPhoneNumber.frame.size.height+btnPhoneNumber.frame.origin.y+10, popUpMainView.frame.size.width, 45)];
[btnEmail setTitle:#"support#vurify.com" forState:UIControlStateNormal];
[btnEmail setTitleColor:Black forState:UIControlStateNormal];
btnEmail.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
btnEmail.titleLabel.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:18];
[btnEmail addTarget:self action:#selector(emailSupport:) forControlEvents:UIControlEventTouchUpInside];
[popUpInsideView addSubview:btnEmail];
}
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
[self removeFromSuperview];
}
-(IBAction)callSupport:(id)sender{
NSString *phoneNumber = [#"tel://" stringByAppendingString:#"180023456789"];
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber] options:#{} completionHandler:^(BOOL success)
{
if (success) {
NSLog(#"Opened url");
}
}];
}
-(IBAction)emailSupport:(id)sender{
[self removeFromSuperview];
}
//call the method like this wherever you want to call
//IN APP DELEGATE
UIView *rectView;
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[rectView removeFromSuperview];
rectView = [[VurifyAppValidation alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT)];
[self.window addSubview:rectView];
}

IOS. UITabBarController with navigationController

I had a viewController which contains video view and UITabBarController. UITabBarController contains 3 viewControllers with UINavigationController. The problem is that the frame of first UINavigationController is good (0,20,width,height), but the other two navigationController has wrong frame (0,0,width,height). Status bar is showing, so I don't know what's wrong with them.
Here i create TabBarController :
#interface EEMenuTBC ()
#end
#implementation EEMenuTBC
- (void)viewDidLoad {
[super viewDidLoad];
EEFavoritesVC *favotiteVC = [[EEFavoritesVC alloc] initWithNibAsClassName];
UINavigationController *favotiteNC = [[UINavigationController alloc] initWithRootViewController:favotiteVC];
[favotiteVC.tabBarItem setImage:[UIImage imageNamed:#"favoritesMenuDisabled"]];
[favotiteVC.tabBarItem setTitle:#"Favourites"];
EESearchTVC *searchVC = [[EESearchTVC alloc] initWithNibAsClassName];
UINavigationController *searchNC = [[UINavigationController alloc] initWithRootViewController:searchVC];
[searchVC.tabBarItem setImage:[UIImage imageNamed:#"searchMenuDisabled"]];
[searchVC.tabBarItem setTitle:#"Search"];
EESettingsTVC *settingsVC = [[EESettingsTVC alloc] initWithNibAsClassName];
UINavigationController *settingsNC = [[UINavigationController alloc] initWithRootViewController:settingsVC];
[settingsVC.tabBarItem setImage:[UIImage imageNamed:#"settingsMenuDisabled"]];
[settingsVC.tabBarItem setTitle:#"Settings"];
self.viewControllers = #[favotiteNC, searchNC, settingsNC];
self.tabBar.items[0].selectedImage = [UIImage imageNamed: #"favoritesMenuEnabled"];
self.tabBar.items[1].selectedImage = [UIImage imageNamed: #"searchMenuEnabled"];
self.tabBar.items[2].selectedImage = [UIImage imageNamed: #"settingsMenuEnabled"];
for(UIView *temp in self.tabBar.subviews) {
[temp setExclusiveTouch:YES];
}
}
-(BOOL)prefersStatusBarHidden {
return NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)goToRootVC {
if (_delegateMenuTBC && [_delegateMenuTBC respondsToSelector:#selector(EEMenuTBCDelegateGoToRootVC)]) {
[_delegateMenuTBC EEMenuTBCDelegateGoToRootVC];
}
}
#end
In other ViewController i doing
_menuTBC = [[EEMenuTBC alloc] initWithNibName:#"EEMenuTBC" bundle:nil];
_menuTBC.view.frame = self.view.frame;
And in favotiteVC navigation look's good, and all other's 2 navigations has no spacing from status bar
P.S
First of all, I added my UITabBarController as a child to UIViewController. The first UINavigationController from UITabBarController has right frame (0,20,width,height) , but others 2 UINavigationsControllers, has wrong frame (0,0,width, height). I think they don't have status bar, and I checked that method -prefersStatusBarHidden isn't call from all UIViewControllers which contains in UITabBarController

iOS How can I set transparent in Container viewcontroller

I had embed UIPageViewController in the Root Viewcontroller.
Like below photo .
But I want to set First,second View controller background transparent, and it's still can show view controller text 1 and 2.
So It will show Root background color(black) and the root view controller can swipe though the uipageviewcontroller.
My pageviewcontroller part code below:
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor clearColor];
UIViewController *p1 = [self.storyboard
instantiateViewControllerWithIdentifier:#"Intro1ID"];
UIViewController *p2 = [self.storyboard
instantiateViewControllerWithIdentifier:#"Intro2ID"];
myViewControllers = #[p1,p2];
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}
Have anyone can teach me how to set the containerview background color transparent and can show 1 , 2 text?
(It is sample code, so that just 1, 2 text)
thank you very much.
This should do the trick:
[[p1 view] setBackgroundColor:[UIColor clearColor]];
[[p2 view] setBackgroundColor:[UIColor clearColor]];
The issue is that the background view of your UIViewController was not transparent.

UITabbar disappears when i push view controller

This is my app delegate:
// Initialize your five tab controllers. with each tab has its own navigation controller
HomePageView *homePageView = [[HomePageView alloc]init];
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:homePageView];
[nav1.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
// Set nav Bar to be completely transparent
[nav1.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav1.navigationBar.shadowImage = [UIImage new];
nav1.navigationBar.translucent = YES;
//Set Title
nav1.tabBarItem.title = #"Home";
ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];
// Set Title
nav2.tabBarItem.title = #"Profile";
// Set nav Bar to be completely transparent
[nav2.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav2.navigationBar.shadowImage = [UIImage new];
nav2.navigationBar.translucent = YES;
FeedViewController *feedViewController=[[FeedViewController alloc]init];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:feedViewController];
// Set nav Bar to be completely transparent
[nav3.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav3.navigationBar.shadowImage = [UIImage new];
nav3.navigationBar.translucent = YES;
// Set Title
nav3.tabBarItem.title = #"Feeds";
ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:listeningSessionViewController];
// Set nav Bar to be completely transparent
[nav4.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav4.navigationBar.shadowImage = [UIImage new];
nav4.navigationBar.translucent = YES;
// set Title
nav4.tabBarItem.title = #"Mussion";
RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];
UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:recievedViewController];
// Set nav Bar to be completely transparent
[nav5.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav5.navigationBar.shadowImage = [UIImage new];
nav5.navigationBar.translucent = YES;
// Set Title
nav5.tabBarItem.title = #"Recieved";
// Set selected tab bar background
UIImage *whiteBackground = [UIImage imageNamed:#"whiteBackground"];
[[UITabBar appearance] setSelectionIndicatorImage:whiteBackground];
self.tabC.tabBar.translucent = YES;
// initialize tabbarcontroller,set your viewcontrollers and change its color.
self.tabC = [[UITabBarController alloc]init];
NSArray* controllers = [NSArray arrayWithObjects: nav1,nav2,nav3,nav4,nav5, nil];
[self.tabC setViewControllers: controllers animated:NO];
//[_window addSubview:self.tabC.view];
[self.window setRootViewController:self.tabC];
// Show window
[self.window makeKeyAndVisible];
return YES;
}
When i push a view controller from one of the tabbar controllers eg HomePageView, The tabbar disappears:
SearchSongViewController *Search_MusicTableView = [[SearchSongViewController alloc] init];
Search_MusicTableView.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self.navigationController presentModalViewController:Search_MusicTableView animated:YES];
When i present the modal view or even push another view controller, the tabbar disappears, please why is this ? and how do i fix it, Thanks alot !

Resources