iAd always showing at bottom of view controller - view

I am trying to have my bannerad show at the top of my view controller above my tableview which is also in my view controller. Additionally, I'm using navigation controller and tab bar controller. When the ad becomes available, I want the ad to slide from the top and push my tableview down by the height of the banner ad (50px). I've had a heck of a time doing this! I've tried a ton of different tutorials and techniques and i can't get any to work like i want.
At this, point, I am just trying to load the ad at the top and I have very simple code but it is always at the bottom behind the tab bar no matter what i do. any assistance to accomplish my object is GREATLY appreciated! Additionally, if i drag bannerad object from storyboard, above my tableview controller, then that works, but I'm left with white space when no ad loads. So, i think i have to do this programmatically but struggling here.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 50, 320, 50)];
[self.view addSubview:adView];
}

I figured this out so am posting my answer in case anyone needed it:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, 50);
//Moves tableview down when banner becomes available
m_tableView.frame = CGRectMake(0,50,320,464);
[UIView commitAnimations];
self.bannerIsVisible = YES;
NSLog(#"Got Banner");
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
banner.frame = CGRectOffset(banner.frame, 0, -50);
//Moves tableview back up when banner is unavailable
m_tableView.frame = CGRectMake(0,0,320,504);
[UIView commitAnimations];
self.bannerIsVisible = NO;
NSLog(#"Got NO Banner");
}
}

Related

Bar Button Item Fade In/Out?

Is there any way to fade a bar button item, as there is no .alpha attribute to set. I'm interested in fading a button out and fading another button in to take its place on the navigation bar. Is there any way to do this?
EDIT: I am trying to fade the top right Bar Button Item
I understand fading is usually accomplished with the .alpha as I stated before.
My issue is for a Bar Button Item there is NO alpha attribute.
As seen here:
As opposed to a normal button where there is an .alpha attribute:
How can I fade a Bar Button Item?
Easy. You would have to create an outlet for them both then create if statements or whatever method you want to initiate the fade in/ fade out animations:
- (void) animateButton {
button1.alpha = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:.5];
button1.alpha = 1;
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
}
- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
button1.alpha = 0;
[UIView commitAnimations];
}
swift
viewDidLoad {
self.button1.alpha = 1
self.button2.alpha = 0
}
When you call Animation Code:
UIView.animateWithDuration(1.0, animations: {
self.button1.alpha = 0
})
// Changing buttons based on UIControlState: You can also do this in storyboard by dragging a bar button item to your view controller and ctrl+drag to your .h file to create an outlet and then commit your animations or code based on what you want.
UIImage *backButtonImage = [[UIImage imageNamed:#"button_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 6)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

UiScrollView scrolling UiView

in my viewcontroller entered all the objects in a scrollview. One of the buttons inside the scrollView creates an animation.
The scrollView get off the page -80.0 orgine.y
So far so good .. Now I want that when you click on the button the scrollview and then goes back down to -80.0 to +80.0 automatically returning to its original position so ... Can you tell me the best method for you to have this?
This is the action that fulfills my button when pushed ...
- (IBAction)AcceptFriendRequest:(id)sender {
PFObject *SelectedUser = [self.UtentiInAttesa objectAtIndex:[sender tag]];
[SelectedUser setObject:#"Confermato" forKey:#"STATO"];
[SelectedUser saveInBackground];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.2];
[UIView setAnimationBeginsFromCurrentState:YES];
FFScrollView.frame = CGRectMake(FFScrollView.frame.origin.x, (FFScrollView.frame.origin.y - 80.0), FFScrollView.frame.size.width, FFScrollView.frame.size.height);
[UIView setAnimationRepeatAutoreverses:YES];
[UIView commitAnimations];
}
In your button event handler
- (IBAction)myBtnClicked:(id)sender {
// Create new CGRect indicate place where you would scroll to.
// Assume it is called `originalRect`
// Use the following method, it should work
[FFScrollView.scroll scrollRectToVisible:originalRect animated:YES];
}

Display Image To Extend Splash Screen Using Storyboards in iPhone SDK

I have this app that has tabs and each tab's root view controller is a navigation controller. I want to display my splash screen or launch image while the app is busy parsing JSON and loading it up in my core data stack and remove it from superview using a fade out animation. I tried this code to make it work but I'm stuck since the image is only displayed on the view inside the navigation controller. What I wanted is to view it full screen with the status bar on top like what you see when launching an app.
_launchImageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
if (kFourInchDevice) {
_launchImageView.image = [UIImage imageNamed:#"Default-568h#2x.png"];
}
[self.view addSubview:_launchImageView];
[self.view bringSubviewToFront:_launchImageView];
And this is my code when dismissing it:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(launchImageFadeAnimationDidFinished)];
_launchImageView.alpha = 0.0;
[UIView commitAnimations];
- (void)launchImageFadeAnimationDidFinished
{
[_launchImageView removeFromSuperview];
}
Any ideas on how to do this? Thanks!
I think you are having problem of hiding NavBar in splash screen isnt it ?
Just Add one extra ViewController in your story board.
Then under Utilities ( left side bar ) under Attribute Tab - View Controller make VC initial View Controller.
Call following in your View Did Load
- (void) hideNavBar {
UINavigationBar *navBar = self.navigationController.navigationBar;
navBar.hidden = TRUE;
}
Then when you you finish your json parser -
#pragma mark - Delegates
#pragma mark JSON Request
-(void) connectionReady; {
NextVC *viewController = [self.storyboard
instantiateViewControllerWithIdentifier:#"NextVC"];
[self.navigationController pushViewController:viewController
animated:YES];
}
Then finally in NextVC
- (void) showNavBar {
UINavigationBar *navBar = self.navigationController.navigationBar;
navBar.hidden = FALSE;
}

Change pushViewController animation direction

i read alot about faking the animation of pushViewController, but I'm wondering if there is a way to change the actually animation, because I would like to use the navBar and the BackButton of the navigationController.
Currently I'm using this to animate:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:YES];
[views setContentSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height -40)];
CGRect frame = views.frame;
frame.origin.y = - self.view.bounds.size.height;
[UIView beginAnimations:#"viewSlideUp" context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
views.frame = frame;
[UIView commitAnimations];
}
but I get an overlapping effect, so my view isn't sliding up, the view is sliding away to the top left side.
Has anyone dealed with that problem? Thx for any kinda help!

Xcode: Why does my flip animation flip twice?

I'm having a little problem. I have an UILabel which have an UILongPressGestureRecognicer. When the UILongPressGestureRecognizer is called my app is supposed to switch to a new view using a flip animation.
This is the code I have used for the GestureRecognizer:
UILongPressGestureRecognizer *labelLongPressRecognizer;
labelLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(LoadLabelSettings:)];
labelLongPressRecognizer.numberOfTouchesRequired = 1;
labelLongPressRecognizer.minimumPressDuration = 2.0;
[NewLabel addGestureRecognizer:labelLongPressRecognizer];
and this is the code for the view switching animation:
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[self.view addSubview:LabelSettingsViewController.view];
[UIView commitAnimations];
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight || self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
LabelSettingsViewController.view.frame = CGRectMake(0, 0, 480, 300);
}
My problem is that when I hold down on my UILabel the switch animation begins, but when I release it repeats the animation again. So basically the animation occur twice and I only want it to take place once.
Any ideas?
Thanks in advance :)
Are you checking the sender state, e.g.,
- (void)LoadLabelSettings:(UILongPressGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded) // or whatever
// then do the flipping stuff
}
Check out the "Overview" of the "UILongPressGestureRecognizer Class Reference", which talks about the long press being continuous and I presume numerous events could be triggered:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UILongPressGestureRecognizer_Class/Reference/Reference.html

Resources