google admob not clickable inside rectangle - iphone

I'm making one app in phone-gap so I've to deal in web-views only. In this app I need to put ads in the bottom of the screen. I'm using google admob for this. This generates floating ad window. I've put this window in bottom of the screen but problem is my webview content is hiding behind this window.
So, I've make one rectangle and add this google admob window in this rectangle. It solved my data hiding problem, but now it is not click able.
My code:
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
theWebView.backgroundColor = [UIColor blackColor];
CGRect viewBounds = CGRectMake([[UIScreen mainScreen] applicationFrame].origin.x, [[UIScreen mainScreen] applicationFrame].origin.y, [[UIScreen mainScreen] applicationFrame].size.width, [[UIScreen mainScreen] applicationFrame].size.height-CGSizeFromGADAdSize(kGADAdSizeBanner).height);
self.view.frame = viewBounds;
CGPoint origin = CGPointMake(0.0,theWebView.frame.size.height);
bannerView_ = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner origin:origin] autorelease];
bannerView_.adUnitID = #"___ADMOBID___";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
return [super webViewDidFinishLoad:theWebView];
}
How to make admob clickable inside rectangle (CGRect)???
Thanks in advance...

You're actually making the main view smaller, which basically - I guess - rescales its contents (including the webview Then you're placing the banner view right under the webview, but it'll show up anyways as you most probably have the clipsToBounds flag set to NO in your main view.
What you need to do is to make the webview (not the main view) smaller using CGRectGetHeight(self.view.bounds) - CGRectGetHeight(kGADAdSizeBanner) (and not the application frame) and then lay them both out accordingly.
Check the self.view.clipsToBounds flag and set it to YES whether in code or in IB in order to test correct behaviour, what you don't see in screen won't get any touches.

Related

How to resize webview according to screen resolution in iphone app?

I am using storyboards. I am unable to resize webview according to the screen size in my storyboard.
I want header to be of same size for both resolution but change the height of webview according to screen resolution.
I can't use Autolayout because I want to deploy my app for ios5 and above.
Please help.
you can set Your Webview frame according to UIScreen like Bellow where you alloc your `webview
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webFrame.origin.y -= 20.0; // statusbar 20 px cut from y of frame
webView = [[UIWebView alloc] initWithFrame:webFrame];
webView.scalesPageToFit = YES;
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
[webView setBackgroundColor:[UIColor clearColor]];
In your .m file under viewDidLoad add this code.
webview.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.he‌​ight);
Add a referencing outlet of your web view to webView and then that should set the webView height to your view height.
Explanation: The view will get longer when you deploy to a 4 inch simulator causing the webView to change to the view's size.

My view is displaying y=-20 dispite its frame set to y=0. After rotation it snaps back to y=0

I started by creating a universal window based app. Starting with the iPhone version I created a UIViewController and associated nib.
My App delegate:
rootViewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
[window makeKeyAndVisible];
[window addSubview:rootViewController.view];
return YES;
My RootViewController:
- (void)viewDidLoad {
[super viewDidLoad];
adBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero()];
[self.view addSubview:adBannerView];
}
I've tried instanciating buttons instead of the adBanner and I get the same result.
My RootViewController's nib has not been changed since x-code created it for me.
My MainWindow_iPhone.xib also is stock.
What's causing this?
Update
After changing the app's orientation the adBannerView (or button...) will snap into the correct place at y=0. I've tried setting adBannerView's y location to 20 presumably to compensate for the status bar and that makes everything display correctly until I change orientation. Then everything moves down 20 pixels and will leave a 20 pixel space between the adBannerView and the status bar.
Try to add the next line in your viewDidLoad (right after [super viewDidLoad];):
self.view.frame = [[UIScreen mainScreen] applicationFrame];
CGRectZero is literally a zero rect (0, 0, 0, 0), so ADBannerView should never show up if it really has a width and height of 0. You probably want to try initWithFrame:self.view.frame or so…
You should set the size identifier before adding the view:
- (void)viewDidLoad {
[super viewDidLoad];
adBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero()];
if(UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
adBannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
else
adBannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;
[self.view addSubview:adBannerView];
// now you can treat it like any other subview
// For example, if you want to move it to the bottom of the view, do this:
CGRect frame = adBannerView.frame;
frame.origin.y = self.view.frame.size.height - frame.size.height;
[adBannerView setFrame:frame];
}
Whenever the interface rotates, you should notify the banner to change its size.
Assuming you have access to WWDC videos (which is available for free), check video session 305. It demos adding the banner.

UIScreen applicationFrame returning incorrect rectangle on landscape application launch (iPhone/iPad)

Having trouble getting the correct bounds for my iPad application when launching it in landscape mode. I have the proper keys set in my Info.plist file, and my view controllers launch properly in landscape (and portrait, natch).
In my applicationDidFinishLaunching: method I'm calling a selector after a 3 second delay, and that method makes a call to [[UIScreen mainScreen] applicationFrame], but it's returning me a portrait frame (ie height > width).
Does anyone know how to fix this? It smells like a bug to me (if so I'll file a radar), but if it's intended behaviour, where is it documented?
I never rely on [[UIScreen mainScreen] applicationFrame], especially during app launch.
When creating views in code, use the superview to set your frame.
If you're using xibs with "simulated interface elements" they will be correctly sized and everything will work great.
UINavigationController based apps
In the case of a UINavigationController based app, grab the frame directly from self.navigationController.view, don't try to use [self loadView] and self.view.superview. UINavigationController uses "hidden" subviews to do it's job--so the direct superview will not work.
UINavigationController is special because during app launch, the navigation controller resizes your views after loadView gets called. When autoresizing kicks in you end up with a small margin at the bottom of the screen.
Why not UIScreen
[[UIScreen mainScreen] applicationFrame] doesn't work reliably (especially during app launch in landscape). My experience is that the viewcontroller's interfaceOrientation property will not match the applicationFrame orientation.
CGRect bounds = [[UIScreen mainScreen] bounds]; // portrait bounds
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
bounds.size = CGSizeMake(bounds.size.height, bounds.size.width);
}
When you are holding the iPad in landscape orientation and launch an app, the view controller initially sees bounds for a portrait view (even though orientation reports landscape). The view controller will then get a message to rotate to landscape orientation before it appears.
This is the way I get the correct CGRect when the view controller is on landscape:
CGRect landscapeBounds;
if (self.view.frame.size.width < self.view.frame.size.height)
landscapeBounds = CGRectMake(self.view.frame.origin.y, self.view.frame.origin.x, self.view.frame.size.height, self.view.frame.size.width);
else
landscapeBounds = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
This is as designed. You should query the size of your superview and adjust as necessary.
[[UIScreen mainScreen] applicationFrame] will always return the portrait rectangle even if the app is in landscape mode. This is related to the fact that UIWindow never actually rotates, but just changes the transform of rootViewController.view instead.
To make sure, you can print the root view object in portrait and landscape modes, and you'll see something like this:
Portrait:
<UIView: 0x96290e0; frame = (0 20; 768 1004); ...
Landscape:
<UIView: 0x96290e0; frame = (0 20; 768 1004); transform = [0, 1, -1, 0, 0, 0]; ...
So, add a launch image and give it the suffix -568h, according to Apple's guides.
I don't understand why anyone with a sound mind would make a system setting depend on a graphic; but I just tested and it worked.
Here is the spot that taught me after a quick search I didn't see this answer above, figured it'd be useful to someone.
S
I got into same problem when dismissing view with dismissViewControllerAnimated in Cordova plugin.
I modified singingAtom code for viewWillAppear method in MainViewController, which got resized after dismissing modal view:
- (void)viewWillAppear:(BOOL)animated
{
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
UIDeviceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIDeviceOrientationLandscapeLeft == orientation ||
UIDeviceOrientationLandscapeRight == orientation)
{
if (appFrame.size.width < appFrame.size.height)
{
appFrame = CGRectMake(appFrame.origin.y, appFrame.origin.x, appFrame.size.height, appFrame.size.width);
}
}
self.view.frame = appFrame;
[super viewWillAppear:animated];
}

addSubview outside resized frame

I've coded a "generic" ads management class for all my applications and i have an issue. This class can add an ads view to any view of my application, randomly; in order to do so, my idea is to resize the frame of my current view to reduce its height (let's say 50 pixels less) and add my ads view in the free space i created. This way, i don't have to bother modifying my views for ads integrations, everything is done automatically. It's working well but my ads aren't responding to touch events. I guess it's because this ads view is "outside" the frame of my controller.
It is possible to reduce the height of my view frame and raise its bounds so my ads subview is really part of my view?
Thanks a lot :)
UIView *adView = [[UIView alloc] init];
adView.frame = CGRectMake(0,267,320,100);
adView.backgroundColor = [UIColor grayColor];
adView.tag = 123456;
adView.userInteractionEnabled = YES;
CGRect myFrame = [self.view frame];
myFrame.size.height = myFrame.size.height - 100;
[self.view setFrame:myFrame];
[self.view addSubview:adView];
Here's a picture representing what i would like to do :
http://i49.tinypic.com/2iw7lz4.jpg
This is not an answer but I do not have option to post a comment to your question.
Can you please post the code you have in your touchesBegan method?
I think there can be the problem
Regards
Alejandra

iPhone, rotated + EAGLView, rotated =

...frustration. I want my game to be run only in landscape mode. I have added the appropriate key/value to the Info.plist file that forces the device orientation to be correct at launch.
I'm now trying to rotate the OpenGL coordinate space to match that of the device. I'm trying to use the code I found here, but it's not working. My test case draws a square at the center, and with all of that code included, I see nothing drawn; if I comment out the 2nd part (only setting the GL_PROJECTION matrix mode), the coordinate system does appear to be correct. But I'd like it rotated as well. I'm a little puzzled on how to do this, as well as setting up the view nib correctly as well. Tips, please?
Also, in the future, I'm going to be swapping out the EAGLView with another UIView subclass; is doing this going to require anything different?
Thanks!
randy
You have the plist set correctly.
Now make sure ALL your view controllers have the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight) ? YES : NO;
}
A child view without it can muck things up.
Also if you have a UINavigationController or similar you NEED to subclass it and implement shouldAutorotateToInterfaceOrientation because its dead stupid on its own and will default to portrait and ruin things.
Then for viewdidload
- (void)viewDidLoad {
[super viewDidLoad];
CGRect rect = [[UIScreen mainScreen] bounds];
rect.size.height = 320;
rect.size.width = 480;
rect.origin.x = 0;
rect.origin.y = 0;
glView = [[EAGLView alloc] initWithFrame:rect pixelFormat:GL_RGB565_OES depthFormat:GL_DEPTH_COMPONENT16_OES preserveBackbuffer:NO];
[self.view addSubview: glView];
[glView addSubview: minimapView];
//etc...
}

Categories