iPhone 5 Layout for a bar hiding within a view - iphone

I wonder if anyone could kindly assist, I am trying to adjust my app so that it recognises the full screen of the iPhone 5, it all works fine on other screens now, however my initial screen I am having an issue with, as I fade the top and bottom bars out of view, the top works fine however the bottom does not, could anyone assist with the code to help me get it to work on the iPhone 5? As right now, the bar is too high on the screen on iPhone 5 and does not fade out of view...
- (void)barwillGo
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
CGRect top = CGRectMake(0, -51, 320, 50);
if (CGRectEqualToRect(topBar.frame,top))
{
[topBar setFrame:CGRectMake(0, 0, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 430, 320, 50)];
}
else {
[topBar setFrame:CGRectMake(0, -51, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 481, 320, 50)];
}
}
completion:nil];
}
else {
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
CGRect top = CGRectMake(0, -51, 768, 50);
if (CGRectEqualToRect(topBar.frame,top))
{
[topBar setFrame:CGRectMake(0, 0, 768, 50)];
[bottomBar setFrame:CGRectMake(0, 974, 768, 50)];
}
else {
[topBar setFrame:CGRectMake(0, -51, 768, 50)];
[bottomBar setFrame:CGRectMake(0, 1025, 768, 50)];
}
}
completion:nil];
}
}

You hard coded the CGRect values of the bottomBar to the 3.5 inch screen dimensions.
Try something like this within your first animation block:
CGRect bounds = topView.superview.bounds;
CGFloat topRectY, bottomRectY;
if(topBar.frame.origin.y == -50){
topRectY = 0;
bottomRectY = bounds.size.height - 50;
} else {
topRectY = -50;
bottomRectY = bounds.size.height;
}
topBar.frame = CGRectMake(0, topRectY, bounds.size.width, 50);
bottomBar.frame = CGRectMake(0, bottomRectY, bounds.size.width, 50);

CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
CGRect top = CGRectMake(0, -51, 320, 50);
if (CGRectEqualToRect(topBar.frame,top))
{
[topBar setFrame:CGRectMake(0, 0, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 430, 320, 50)];
}
else {
//check device iphone5 or not
if (screenHeight != 568.0f) {
[topBar setFrame:CGRectMake(0, -51, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 481, 320, 50)];
}
else
{
[topBar setFrame:CGRectMake(0, -51, 320, 50)];
[bottomBar setFrame:CGRectMake(0, 569, 320, 50)];
}
}
}
completion:nil];
}

Related

Position UIView above status bar

I am trying to get a UIView to sit on top of the status bar, but currently have had no success. I have tried the following:
view.window?.windowLevel = UIWindowLevelStatusBar + 1 // view being a UIView() object
I have also tried:
let win: UIWindow = UIWindow( )
win.frame = CGRect( x: 0, y: 0, width: 100, height: Display.height )
win.windowLevel = UIWindowLevelStatusBar + 1
win.hidden = false
win.backgroundColor = UIColor.blueColor()
win.makeKeyAndVisible()
In all cases the status bar is still on top. Has anyone got this to work in Swift yet?
This is my simple solution (you can also use MTStatusBarOverlay - check git hub).
first initialise the window. Do that after you set makeKeyAndVisible on your main window.
self.syncMessageWindow = [[UIWindow alloc] initWithFrame:messageRect];
self.syncMessageWindow.clipsToBounds = YES;
self.syncMessageWindow.frame = messageRect;
self.syncMessageWindow.windowLevel = UIWindowLevelStatusBar+1.f;
self.syncMessageWindow.alpha = 1.f;
self.syncMessageView = [[UIView alloc] initWithFrame:messageRect];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 2, messageRect.size.width-20, 16)];
[label setTag:100];
[label setTextAlignment:NSTextAlignmentCenter];
[label setFont:[UIFont fontWithName:#"HelveticaNeue" size:12.0]];
[label setTextColor:[UIColor whiteColor]];
[self.syncMessageView addSubview:label];
[self.syncMessageWindow addSubview:self.syncMessageView];
[self.syncMessageWindow setRootViewController:[UIApplication sharedApplication].delegate.window.rootViewController];
[self.syncMessageWindow makeKeyAndVisible];
self.syncMessageWindow.hidden = YES;
than show the message
if(self.syncMessageWindow.hidden == YES) {
self.syncMessageWindow.hidden = NO;
[self.syncMessageView setBackgroundColor:color];
[self.syncMessageView setAlpha:1.0];
[self.syncMessageView setFrame:CGRectMake(0, -20, self.syncMessageView.frame.size.width, self.syncMessageView.frame.size.height)];
[self.syncMessageWindow setWindowLevel:UIWindowLevelStatusBar+1];
[((UILabel*)[self.syncMessageView viewWithTag:100]) setText:message];
[UIView animateWithDuration:.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.syncMessageView.frame = CGRectMake(0, 0, self.syncMessageView.frame.size.width, self.syncMessageView.frame.size.height);
} completion:^(BOOL finished) {
[UIView animateWithDuration:.3 delay:2.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.syncMessageView.frame = CGRectMake(0, -20, self.syncMessageView.frame.size.width, self.syncMessageView.frame.size.height);
} completion:^(BOOL finished) {
[self.syncMessageWindow setWindowLevel:UIWindowLevelNormal];
self.syncMessageWindow.hidden = YES;
}];
}];
}
Why don't you hide the status bar? Then you can put the view at the top. See How to hide iOS status bar.
I don't think it is possible to cover the status bar with another view, because all content is behind the status bar by default.

How to initiate revmob banner ad with exact frame and placement ID?

I tried using the suggested code from RevMob to show a banner ad with a specific placement ID without success, tried this code:
RevMobAds *revmob = [RevMobAds revMobAds];
RevMobBanner *banner = [revmob bannerWithPlacementId:#"ID_FROM_REV_MOB"];
[banner showAd];
Tried even to add the following statement
if (IS_iPad) {
banner.frame = CGRectMake(0, 958, 768, 66);
} else if (IS_WIDESCREEN){
banner.frame = CGRectMake(0, 518, 320, 50);
} else {
banner.frame = CGRectMake(0, 430, 320, 50);
}
but no success, the only way I could be able to show banner ads was this:
[RevMobAds showBannerAdWithFrame:CGRectMake(0, 958, 768, 66) withDelegate:self];
But it didn't help to add the placement ID.
I think you need to do it as the following by using the RevMobBannwerView instead:
RevMobAds *revmob = [RevMobAds revMobAds];
RevMobBannerView *revBannerView = [revmob bannerViewWithPlacementId:#"ID_FROM_REV_MOB"];
if (IS_iPad) {
revBannerView.frame = CGRectMake(0, 958, 768, 66);
} else if (IS_WIDESCREEN){
revBannerView.frame = CGRectMake(0, 518, 320, 50);
} else {
revBannerView.frame = CGRectMake(0, 430, 320, 50);
}
[revBannerView loadAd];
[self.view addSubview:revBannerView];
[self.view bringSubviewToFront:revBannerView];
When I'm adding it(RevMob version 5.9) in my project. I do it like this:
[RevMobAds startSessionWithAppID:#"my id"];
RevMobBannerView *ad = [[RevMobAds session] bannerView]; // you must retain this object
[ad loadWithSuccessHandler:^(RevMobBannerView *banner) {
banner.frame = CGRectMake(0, 381, 320, 50);
[self.window.rootViewController.view addSubview:banner];
NSLog(#"Ad loaded");
} andLoadFailHandler:^(RevMobBannerView *banner, NSError *error) {
NSLog(#"Ad error: %#",error);
} onClickHandler:^(RevMobBannerView *banner) {
NSLog(#"Ad clicked");
}];

UIView in UIAlert

I want to show UIView in UIAlert and alert should be display in all another view and also when application running in background. Is it Possible ? if No then how can i do it?
Try This Code :-
In view didload Method :
-(void)viewDidLoad
{
flag=YES;
[super viewDidLoad];
}
In viewWillAppear Method :
-(void)viewWillAppear:(BOOL)animated
{
v=[[UIView alloc]initWithFrame:CGRectMake(0, 490, 320, 300)];
v1.layer.cornerRadius = 10.0;
v1.clipsToBounds = YES;
v1.frame=CGRectMake(0, 490, 320, 108);
}
And
-(IBAction)btn_Clicked
{
if (flag == NO)
{
v=[[UIView alloc]initWithFrame:CGRectMake(0, 490, 320, 300)];
v1.layer.cornerRadius = 10.0;
v1.clipsToBounds = YES;
v1.frame=CGRectMake(0, 490, 320, 108);
v.hidden=NO;
v.frame=CGRectMake(0, 0, 320, 460);
v.backgroundColor=[UIColor colorWithWhite:0 alpha:0.2];
[self.view addSubview:v];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
v1.frame=CGRectMake(69, 176, 185, 108);
[v addSubview:v1];
[UIView commitAnimations];
}
else
{
v.hidden=NO;
v.frame=CGRectMake(0, 0, 320, 460);
v.backgroundColor=[UIColor colorWithWhite:0 alpha:0.2];
[self.view addSubview:v];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
//v1.backgroundColor=[UIColor colorWithWhite:0 alpha:0.3];
v1.frame=CGRectMake(69, 176, 185, 108);
[v addSubview:v1];
[UIView commitAnimations];
}
}
And
-(IBAction)cancel_Clicked
{
flag=NO;
v.hidden=YES;
}
When your app goes in background you dont have that much access in showing UIAlertView, you can try UILocalNotification.
But I guess you want a custom popup which is your own view.
just try creating a UIView and set properties from Interface Builder. and add as a subview.
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 290, 290)];
[self.view addSubView:v];
but once your app is in background, you can't do anything anymore.
You can add a UIView in UIAlertView,
but application running in background you can't, it 's only the notification style.

beginAnimations: subview's animation slower then view's animation

I have a little problem, I try to display a view with an animation in this way:
self.vistaAiuti = [[UIView alloc] initWithFrame:CGRectMake(10, -200, 300, 200)];
self.vistaAiuti.backgroundColor = [UIColor blueColor];
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
closeButton.frame = CGRectMake(50, 140, 220, 40);
[closeButton setTitle:#"Go back" forState:UIControlStateNormal];
[closeButton addTarget:self action:#selector(closeView:) forControlEvents:UIControlEventTouchUpInside];
[self.vistaAiuti addSubview:closeButton];
[self.view addSubview:self.vistaAiuti];
[UIView beginAnimations:#"MoveView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.5f];
self.vistaAiuti.frame = CGRectMake(10, 0, 300, 200);
[UIView commitAnimations];
and this for close it:
[UIView beginAnimations:#"MoveView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.5f];
self.vistaAiuti.frame = CGRectMake(10, -200, 300, 0);
[UIView commitAnimations];
the problem is that the button on vista aiuto is slower then the vistaAiuti, so when I close the view the button remains behind for some second...what I have to do for for have the same velocitiy?
The problem is that the vistaAiuti frame is being set to zero height in the close animation. The button appears to lag, but what's really happening is that the parent view underneath is shrinking to zero height and -200 origin.y.
Change the close animation target frame to:
self.vistaAiuti.frame = CGRectMake(10, -200, 300, 200);
Also, some other advice:
Separate the creation of the view from showing it. This way you don't add another subview every time you want to show it.
- (void)addVistaAiutiView {
// your creation code
self.vistaAiuti = [[UIView alloc] initWithFrame:CGRectMake(10, -200, 300, 200)];
self.vistaAiuti.backgroundColor = [UIColor blueColor];
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
closeButton.frame = CGRectMake(50, 140, 220, 40);
[closeButton setTitle:#"Go back" forState:UIControlStateNormal];
[closeButton addTarget:self action:#selector(closeView:) forControlEvents:UIControlEventTouchUpInside];
[self.vistaAiuti addSubview:closeButton];
[self.view addSubview:self.vistaAiuti];
}
Use block animation, it's much more compact to write and easy to read
- (BOOL)vistaAiutiIsHidden {
return self.vistaAiuti.frame.origin.y < 0.0;
}
- (void)setVistaAiutiHidden:(BOOL)hidden animated:(BOOL)animated {
if (hidden == [self vistaAiutiIsHidden]) return; // do nothing if it's already in the state we want it
CGFloat yOffset = (hidden)? -200 : 200; // move down to show, up to hide
NSTimeInterval duration = (animated)? 0.5 : 0.0; // quick duration or instantaneous
[UIView animateWithDuration:duration animations: ^{
self.vistaAiuti.frame = CGRectOffset(0.0, yOffset);
}];
}

How can I position my UIView to the bottom of the screen?

I have the following code to show a little notification bar right above a UITabViewController:
- (void)showNotificationBar
{
if(mentionsButton.hidden)
{
//DM button on the left
[dmButton setFrame:CGRectMake(20,-2, 140, 35)];
[directMessagesPill setFrame:CGRectMake(6, 7, 29, 20)];
[dmCountLabel setFrame:CGRectMake(11, 5, 19, 21)];
[directMessagesLabel setFrame:CGRectMake(43, 6, 81, 21)];
//Mentions on the right
[mentionsButton setFrame:CGRectMake(162,-2, 140, 35)];
[mentionsPill setFrame:CGRectMake(161, 7, 29, 20)];
[mentionCountLabel setFrame:CGRectMake(166, 6, 19, 21)];
[mentionsLabel setFrame:CGRectMake(193, 6, 86, 21)];
}
else
{
//Mentions on the left
[mentionsButton setFrame:CGRectMake(20,-2, 140, 35)];
[mentionsPill setFrame:CGRectMake(6, 7, 29, 20)];
[mentionCountLabel setFrame:CGRectMake(11, 5, 19, 21)];
[mentionsLabel setFrame:CGRectMake(43, 6, 81, 21)];
//DM on the right
[dmButton setFrame:CGRectMake(162,-2, 140, 35)];
[directMessagesPill setFrame:CGRectMake(161, 7, 29, 20)];
[dmCountLabel setFrame:CGRectMake(166, 5, 19, 21)];
[directMessagesLabel setFrame:CGRectMake(193, 6, 86, 21)];
}
if(!mentionsButton.hidden && !dmButton.hidden)
notificationDivider.hidden = NO;
if(!self.tabBarController.tabBar.hidden)
{
//CGRect frame = CGRectMake(0, 0, 320, 32);
CGRect frame = CGRectMake(0, 500, 320, 32);
//frame.origin.y = CGRectGetMaxY(self.navigationController.navigationBar.frame) - frame.size.height;
frame.origin.y = self.tabBarController.tabBar.frame.origin.y;
notificationBar.frame = frame;
//[self.navigationController.navigationBar.superview insertSubview:notificationBar belowSubview:self.navigationController.navigationBar];
[self.tabBarController.tabBar.superview insertSubview:notificationBar belowSubview:self.tabBarController.tabBar];
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = notificationBar.frame;
//frame.origin.y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
frame.origin.y -= frame.size.height;
notificationBar.frame = frame;
}];
}
else
{
CGRect frame = CGRectMake(0, 500, 320, 32);
frame.origin.y = self.navigationController.toolbar.frame.origin.y;
notificationBar.frame = frame;
[self.navigationController.toolbar.superview insertSubview:notificationBar belowSubview:self.navigationController.toolbar];
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = notificationBar.frame;
frame.origin.y -= frame.size.height;
notificationBar.frame = frame;
}];
}
}
The problem is, there is a gap between this UIView and a UIToolbar when I switch tabs to a UINavigationController that hides the tabbar. How can I reposition it so that it goes down?
If i have understod your problem correctly this should do:
What I would do is to put the positioning code for the notification bar on another function, since you also insert subviews in this piece of code. You should call it form here and in the view did load methods of this UIViewController and the UINavigationController that you call.
A trick to position correctly the the notification bar without much trouble would be to use the toolbar y position as a reference, since it is updated automatically.
CGrect frame = notificationBar.frame;
frame.y = self.navigationController.toolbar.frame.origin.y - notificationBar.frame.size.height;
notificationBar.frame = frame;
I hope this helps.