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

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");
}];

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.

iPhone 5 Layout for a bar hiding within a view

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];
}

Set Revmob banner frame for iphone

I am using Revmob for showing add banner using below code.
[RevMobAds startSessionWithAppID:#"My Application id"];
[RevMobAds session].testingMode = RevMobAdsTestingModeWithAds;
[[RevMobAds session] showBanner];
and it's showing test banner perfectly at the bottom.
Now my question is i want to set this banner at the top of my application.
so how can i set this banner frame ?
I have tried to use RevMobBannerView
My code is
RevMobBannerView *banner = [[RevMobBannerView alloc]
initWithFrame:CGRectMake(0, 100, 320, 50)];
[banner setBackgroundColor:[UIColor yellowColor]];
[banner loadAd];
[self.window addSubview:banner];
but it's not working...it's not showing anything into screen.
any help will be apriciated...
Thanks !
From RevMob Documentation site:
RevMobBannerView *ad = [[RevMobAds session] bannerView];
ad.delegate = self;
[ad loadAd];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
ad.frame = CGRectMake(0, 0, 768, 114);
} else {
ad.frame = CGRectMake(0, 0, 320, 50);
}
[self.view addSubView:ad];
In case tkanzakic answer didn't work, you can always use a UIView to put the banner into and add it to your view. In banner load delegate, resize your intermediate view to banner's bounds.
edit:
Something like
ad = [[[RevMobAds session] bannerView] retain];
ad.delegate = self;
[ad loadAd];
- (void)revmobAdDidReceive {
intermediateView.frame = CGRectMake(0,0, somewidth, someheight);
ad.frame = intermediateView.bounds;
[intermediateView addSubview:ad];
}
the RevMobAds object has a RevMobBannerView property, and this property has a frame. Accordingly to the documentation:
You can use this property to define the position of the banner in the screen. The default is a banner on the botton of the screen
EDIT:
Try this to set the frame:
RevMobAds *revMovAds = [RevMobAds startSessionWithAppID:#"My Application id"];
revMovAds.bannerView.frame = CGRect(x,y,xx,yy);
[revMovAds showBanner];
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");
}];

Drawing Line in Two Views At a Time

I am doing an app in which i need to draw lines in one view and that automatically should appear in the other view. Any help would be appreciated..
I have tried this..
- (void)viewDidLoad
{
[super viewDidLoad];
slv = [[SmoothLineView alloc] initWithFrame:CGRectMake(DrawingView.bounds.origin.x, DrawingView.bounds.origin.y + 42, DrawingView.bounds.size.width, DrawingView.bounds.size.height - 42)];
slv.delegate = self;
[DrawingView addSubview:slv];
}
-(IBAction)btnAnotherView:(UIButton *)sender
{
[zoomingTypingView setUserInteractionEnabled:YES];
if(sender.tag == 123)
{
[self.view setBackgroundColor:[UIColor colorWithWhite:0.500 alpha:1.000]];
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationTransitionCurlUp
animations:^{
//animation code
zoomingTypingView.frame = CGRectMake(0, 549, 768, 451);
} completion:^(BOOL finished) {
}];
CGRect imageFrame = CGRectMake(50, 50, 220, 120);
ResizableView = [[SPUserResizableView alloc] initWithFrame:imageFrame];
CGRect gripFrame = CGRectMake(50,50, 220,120);
UIView *zoom = [[UIView alloc]initWithFrame:gripFrame];
UIScrollView *zoomscroll = [[UIScrollView alloc]initWithFrame:gripFrame];
[zoomscroll setZoomScale:32.0];
[zoomscroll setMaximumZoomScale:32.0];
[zoom addSubview:zoomscroll];
[ResizableView setContentView:zoom];
ResizableView.delegate = self;
[DrawingView addSubview:ResizableView];
sender.tag = 246;
}
else
{
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationTransitionCurlUp
animations:^{
//animation code
zoomingTypingView.frame = CGRectMake(0, 999, 768, 451);
} completion:^(BOOL finished) {
[self.view setBackgroundColor:[UIColor whiteColor]];
}];
[ResizableView removeFromSuperview];
[DrawingView addSubview:slv1];
sender.tag = 123;
}
}
In the above Image WhiteColored View is the new View and if i draw in that whiteColoredView that should reflect in both the views.
You can get more idea by looking at the NOTE TAKER HD APP.
http://www.youtube.com/watch?v=FdGDnUKZcMM
If you have two views defined:
#property(nonatomic) UIView *view1;
#property(nonatomic) UIView *view2;
instead of do self.view, you can have function does the drawing for one view:
-(void)drawView:(UIView*)view{
//your drawing code here
}
And just call the same function twice with passing different views.

how can i resize frame of UIViewController when rotate screen?

I'm developing a program based iPad.
I created new modal UIViewController as formsheet mode not full screen.
And to resize the view, i used following codes.
...
MyController* controller = [[MyController alloc] init];
controller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController : controller animated: YES];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if ( UIInterfaceOrientationIsPortrait(orientation) )
controller.view.superview.frame = CGRectMake(200, 100, 350, 600);
else
controller.view.superview.frame = CGRectMake(100, 200, 600, 350);
...
in MyController, i taked following codeds as didRotateFromInterfaceOrientation.
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if ( fromInterfaceOrientation == orientation )
return;
if ( UIInterfaceOrientationIsPortrait(orientation) )
{
self.view.frame = CGRectMake(0, 0, 350, 600);
self.view.superview.frame = CGRectMake(200, 100, 940, 628);
}
else
{
self.view.frame = CGRectMake(0, 0, 600, 350);
self.view.superview.frame = CGRectMake(100, 200, 600, 350);
}
}
but when rotate screen, the view don't be resized and width and height of superview has unexpect value.
please help my problem.
try to debug it and see what orientation you get in fact.
Did you try like this?
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if ( UIInterfaceOrientationIsPortrait(fromInterfaceOrientation) )
{
self.view.frame = CGRectMake(0, 0, 350, 600);
self.view.superview.frame = CGRectMake(200, 100, 940, 628);
}
else
{
self.view.frame = CGRectMake(0, 0, 600, 350);
self.view.superview.frame = CGRectMake(100, 200, 600, 350);
}
}
Also note that there are two portairt orientations..