I am trying to add a button so the user hide the add, I did this in swift but it seems quite different using objective-c this is the code I am using to display an add
#pragma mark iAd Deligate Methods
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
-(void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
I tried using
- (IBAction)hideAd:(id)sender {
[ADBannerView.hidden = YES];
}
But this doesn't work, any ideas? thanks!
ADBannerView is the class. It doesn't have a hidden attribute for you to set to hide all ads. Instead, grab your banner and do this instead:
banner.hidden = YES;
That is, you need a reference to your banner, as opposed to it being passed in in the other two methods. You should keep a reference to the ad when you created it.
The problem is in your hideAd:(id)sender method.
- (IBAction)hideAd:(id)sender {
[ADBannerView.hidden = YES];
}
ADBannerView is the class of your banner, not the banner itself.
The code below should work fine.
Please note: _banner should be replaced with the property name in which you declared your ADBannerView.
- (IBAction)hideAd:(id)sender {
[_banner setHidden: YES];
}
Related
I have a ViewController which contains a couple of UILabels, a UIImageView and an ADBannerView. There are two relevant movements: The UIImageView rotates based on the angle at which the user is holding their device, and the ADBannerView slides into view based on whether it has an iAD to display.
If the UIImageView is stationary, the ADBannerView slides into view correctly. However, once the UIImageView starts rotating, the ADBannerView disappears. AFAIK the two views are completely independent.
- (void) updateFloatingBar
{
double angleToUpright = [self calculateAngleToUpright];
double newAngle = angleToUpright - self.currentAngle;
[self.FloatingBarImageView setTransform:CGAffineTransformMakeRotation(newAngle*(CGFloat)(M_PI/180))];
}
- (void) hideAd
{
NSLog(#"Ad Hidden");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.adBannerView cache:YES];
self.adBannerView.frame = CGRectMake(0,self.view.bounds.size.height + 50,50,320);
[UIView commitAnimations];
}
- (void) showAd
{
NSLog(#"Ad Shown");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.compassADBannerView cache:YES];
self.compassADBannerView.frame = CGRectMake(0,self.view.bounds.size.height - 50,50,320);
[UIView commitAnimations];
}
Again, the first method works correctly, it just also has the secondary effect of pushing offscreen the adBannerView placed by showAd:
I am making an application, that has iAd, but when I am not connected to the internet the space where the iAd is supposed to be, is a white empty space, how do I make it so the iAd space is not white, and is the same color as the background
If you could give me some code, that will be nice.
Thanks in advance!
Add this in your .m file. This method checks if an Ad can be loaded. If it can't, it uses a nice animation to make the white space disappear. I'm also a noob to iOS programming, but this is how I did it in one app that I have in the App Store. I'm not sure if this is the best way but it works.
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
Check this
iAd sample code
iAd Example
Shared iAd example
I have a UIButton in my code that moves steadily across the screen. Currently, when the user presses the button, the alpha changes to 0 and it just disappears. What I'd like to do is run a separate animation after the button is pressed/it has disappeared. Seems easy enough but the catch is I need to run the animation at the exact point of the button when it is pressed. And I'm drawing a blank on how to make this happen. Any help will be much appreciated! I'll post some relevant code below.
-(void)movingbuttons{
movingButton2.center = CGPointMake(x, y);
displayLink = [CADisplayLink displayLinkWithTarget:self selector:#selector(moveObject)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}
-(void)moveObject{
movingButton2.center = CGPointMake(movingButton2.center.x , movingButton2.center.y +1);
}
-(IBAction)button2:(id)sender {
[UIView beginAnimations:nil context:NULL];
[movingButton2 setAlpha:0];
[UIView commitAnimations];
}
Replace your button2 action with below code and implement the someOtherMethodWithAnimation method with the animation you want :)
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
movingButton2.alpha = 0;
[UIView commitAnimations];
[self performSelector:#selector(someOtherMethodWithAnimation) withObject:nil afterDelay:1.0];
Replace your animation with:
[UIView animateWithDuration:0.25
animations:^{
self.movingbutton2.alpha = 0.0;
// modify other animatable view properties here, ex:
self.someOtherView.alpha = 1.0;
}
completion:nil];
Just a nit picking point, but is the button in your view controller's .xib file correctly hooked up to your IBOutlets and IBActions?
UPDATE:
You are not limited to modifying that one button in your method. You add what ever code you want in the animation block (see the udated axample above).
UIView animatable properties, there is an animation section there.
Another approach could be (I am just using alpha as an example):
[UIView animateWithDuration:1.0
animations:^{
self.movingButton2.alpha = 0.0;
}
completion:^{
[UIView animatateWithDuration:0.25
animations:^{
self.someOtherView.alpha = 1.0;
}
completion:nil];
}];
This will more likely guarantee the animations will hapen one after another.
I'm doing some custom animations to change views in a single method. I already removed "fromView" from superView using [UIView setAnimationDidStopSelector:#selector(removeFromSuperview)], but I also want to enable user interaction after the end of the animation.
Here's my code:
-(void) switchFrom:(UIViewController*) fromViewController To:(UIViewController*) toViewController usingAnimation:(int) animation{
UIView *fromView = fromViewController.view;
UIView *toView = toViewController.view;
/*************** SET ALL DEFAULT TRANSITION SETTINGS ***************/
// Get the current view frame, width and height
CGRect pageFrame = fromView.frame;
CGFloat pageWidth = pageFrame.size.width;
// Create the animation
[UIView beginAnimations:nil context:nil];
// Create the delegate, so the "fromView" is removed after the transition
[UIView setAnimationDelegate: fromView];
[UIView setAnimationDidStopSelector:#selector(removeFromSuperview)];
// Set the transition duration
[UIView setAnimationDuration: 0.4];
/*************** IT DOESN'T WORK AT ALL ***************/
[toView setUserInteractionEnabled:NO];
[UIView setAnimationDelegate: toView];
[UIView setAnimationDidStopSelector:#selector(setUserInteractionEnabled:)];
[toView setUserInteractionEnabled:YES];
// Add the "toView" as subview of "fromView" superview
[fromView.superview addSubview:toView];
switch (animation) {
case AnimationPushFromRigh:{
// Position the "toView" to the right corner of the page
toView.frame = CGRectOffset(pageFrame, pageWidth,0);
// Animate the "fromView" to the left corner of the page
fromView.frame = CGRectOffset(pageFrame, -pageWidth,0);
// Animate the "toView" to the center of the page
toView.frame = pageFrame;
// Animate the "fromView" alpha
fromView.alpha = 0;
// Set and animate the "toView" alpha
toView.alpha = 0;
toView.alpha = 1;
// Commit the animation
[UIView commitAnimations];
}
.
.
.
Any idea how can I call this two methods in setAnimationDidStopSelector and actually make them work together?
EDIT 1
Tried #safecase code like this, replacing this commented block:
/*************** IT DOESN'T WORK AT ALL ***************
[toView setUserInteractionEnabled:NO];
[UIView setAnimationDelegate: toView];
[UIView setAnimationDidStopSelector:#selector(setUserInteractionEnabled:)];
[toView setUserInteractionEnabled:YES];
*************** IT DOESN'T WORK AT ALL ***************/
// Remove the interaction
[toView setUserInteractionEnabled:NO];
[fromView setUserInteractionEnabled:NO];
// Create the animation
[UIView animateWithDuration:0.4 animations:^{
[fromView performSelector:#selector(removeFromSuperview)];
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.4
animations:^{
C6Log(#"finished");
[toView performSelector: #selector(setUserInteractionEnabled:)];
}];
}];
The "toView" is removed instead of the "fromView" is removed :(
The buttons continue to be interactive during the animation
Do you know beginIgnoringInteractionEvents and endIgnoringInteractionEvents?
Normally, if you don't want any userInteraction during an animation, you would use those.
Anyway you still need correct callbacks to trigger them.
You need to define your own method, e.g. remove: and pass that as the selector. In the method, just use the passed UIView to remove it.
-(void)remove:(id)sender {
UIView *v = (UIView*)sender;
[v removeFromSuperview];
}
You can use this:
[UIView animateWithDuration:0.4
animations:^{ [self performSelector:#selector(removeFromSuperview)]; // other code here}
completion:^(BOOL finished){ [UIView animateWithDuration:0.4
animations:^{ [self performSelector:#selector(setUserInteractionEnabled:)]; //other code here}]; }];
Hope helpful.
I think u can use to enable user interaction
self.view.userInteractionEnabled=NO;
I ended up creating a Category extension to UIView… and it finally works!
UIView+Animated.h code
#import <UIKit/UIKit.h>
#interface UIView (Animated)
- (void) finishedAnimation;
#end
UIView+Animated.m code
#import "UIView+Animated.h"
#implementation UIView (Animated)
- (void) finishedAnimation{
C6Log(#"FinishedAnimation!");
[self removeFromSuperview];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}
#end
Then, I #imported this extension in my coordinating controller:
C6CoordinatingController.h partial code
#import "UIView+Animated.h"
And called the selector in setAnimationDidStopSelector:
C6CoordinatingController.m partial code
// Create the delegate, so the "fromView" is removed after the transition
[UIView setAnimationDelegate: fromView];
// Ignore interaction events during the animation
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
// Set the transition duration
[UIView setAnimationDuration: 0.4];
// Call UIView+Animated "finishedAnimation" method when animation stops
[UIView setAnimationDidStopSelector:#selector(finishedAnimation)];
So, I ended up using #jaydee3 and #Mundi concepts and it works like a charm!
Thank you guys!
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:4];
[UIView setAnimationDuration:5];
navigation.frame = CGRectOffset(navigation.frame, 0, 430);
[UIView commitAnimations];
Code block above works fine when called manually on viewDidLoad function or with button tap. But when i try to call that block within a selector function like below, animation doesnt effect. Object jumps to position. What would cause to that?
if ([delegate respondsToSelector:#selector(carouselDidEndScrollingAnimation:)])
{
[delegate carouselDidEndScrollingAnimation:self];
}
- (void) carouselDidEndScrollingAnimation:(iCarousel *)carousel{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5];
navigation.frame = CGRectOffset(navigation.frame, 0, 430);
[UIView commitAnimations];
}
icarousel github
Still don't know the real problem but
[self performSelector:#selector(makeAnim) withObject:nil afterDelay:0.0001];
solved my problem.
Hope helps anyone.
Still needs a better solution.