I am new to Adwhirl and am having some problems. I am setting my mainScreen controller as the delegate for AdView. While I am in this view, the ads refresh just fine. When I switch to another view though, the delegate no longer received any new ads(the delegates selectors are not fired). Is there a reason for this? I want one adView for my whole app, so I am passing a pointer around to it everywhere and adding it as a subview to the proper view.
Here is some code:
#pragma mark AdWhirl required delegate methods
- (NSString *)adWhirlApplicationKey {
return MY_AD_WHIRL_APPLICATION_KEY;
}
- (UIViewController *)viewControllerForPresentingModalView {
return self;
}
- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView {
adView.hidden = NO;
if (self.view.window) {
[UIView beginAnimations:#"AdWhirlDelegate.adWhirlDidReceiveAd:"
context:nil];
[UIView setAnimationDuration:0.7];
CGSize adSize = [adView actualAdSize];
CGRect newFrame = adView.frame;
newFrame.size = adSize;
newFrame.origin.x = (self.view.bounds.size.width - adSize.width)/ 2;
newFrame.origin.y = self.view.bounds.size.height - 50;
adView.frame = newFrame;
[UIView commitAnimations];
}else {
[UIView beginAnimations:#"AdWhirlDelegate.adWhirlDidReceiveAd:"
context:nil];
[UIView setAnimationDuration:0.7];
CGSize adSize = [adView actualAdSize];
CGRect newFrame = adView.frame;
newFrame.size = adSize;
newFrame.origin.x = (self.view.bounds.size.width - adSize.width)/ 2;
//newFrame.origin.y = self.view.bounds.size.height - 50;
adView.frame = newFrame;
[UIView commitAnimations];
}
}
-(void)adWhirlDidFailToReceiveAd:(AdWhirlView *)adWhirlView usingBackup:(BOOL)yesOrNo
{
adView.hidden = YES;
}
Note: The mainScreen controller is the one my app starts with..so it is always resident in memory. This is responsible for pushing the other views on screen. Am I missing something to get this working?
Related
In my current project there are two main mechanics. A series of objects that continually move up the screen, and a mechanic where you press multiple buttons to move 2 objects. For the series of objects that move up the screen, i have utilized a CADisplayLink, and for the other mechanic is use a UIAnimation, however when i run my project, i notice that the UIAnimation, interferes with the movement of the Objects linked with the CADisplayLink for a split second whenever a button is pressed. How do I correct this issue??
Below is my code for these two mechanics
-(IBAction)tap{
CGRect frame = Person.frame;
frame.origin.x = 16;
frame.origin.y = 37;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
Person.frame = frame;
[UIView commitAnimations];
}
-(IBAction)tap1{
CGRect frame = Person.frame;
frame.origin.x = 241;
frame.origin.y = 37;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
Person.frame = frame;
[UIView commitAnimations];
}
-(IBAction)tapR1{
CGRect frame = Person1.frame;
frame.origin.x = 302;
frame.origin.y = 37;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
Person1.frame = frame;
[UIView commitAnimations];
}
-(IBAction)tapR2{
CGRect frame = Person1.frame;
frame.origin.x = 526;
frame.origin.y = 37;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
Person1.frame = frame;
[UIView commitAnimations];
}
-(void)GameOver{
}
-(void)Score{
ScoreNumber = ScoreNumber + 1;
ScoreLabel.text = [NSString stringWithFormat:#"%i", ScoreNumber];
}
-(IBAction)StartGame:(id)sender{
StartGame.hidden = YES;
Spike.hidden = NO;
Spike1.hidden = NO;
Spike2.hidden = YES;
SpikeR.hidden = NO;
SpikeR1.hidden = NO;
SpikeR2.hidden = NO;
circle.hidden = NO;
ScoreLabel.hidden = NO;
[self PlaceBars];
[self PlaceBars1];
Movement = [CADisplayLink displayLinkWithTarget:self selector:#selector(BarMoving)];
[Movement addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}
-(void)BarMoving{
Spike.center = CGPointMake(Spike.center.x, Spike.center.y - 5);
Spike1.center = CGPointMake(Spike1.center.x, Spike1.center.y - 5);
Spike2.center = CGPointMake(Spike1.center.x, Spike1.center.y - 5);
if (Spike2.center.y == -115) {
[self PlaceBars];
}
SpikeR.center = CGPointMake(SpikeR.center.x, SpikeR.center.y - 5);
SpikeR1.center = CGPointMake(SpikeR1.center.x, SpikeR1.center.y - 5);
SpikeR2.center = CGPointMake(SpikeR2.center.x, SpikeR2.center.y - 5);
if (SpikeR2.center.y == -115) {
[self PlaceBars1];
}
}
I rekon you use CADisplayLink for all the movement mechanisms.
However, delegate the logic of movement to your objects, instead of having a parent object that manages all movements. This is the pattern that you will see in Unity.
In your case, when CADisplayLink updates, loop through your objects and call update() method on each of them. This update method moves that object up 5 points, like what BarMoving() does, on normal state. On tapped state, it moves to [241, 37] gradually.
When user taps the object, change it state from normal to tapped, setting initial velocity, position algorithms, target point, and update() method mentioned above will handle the tap movement.
I have iAds working almost perfectly using a modified version of UITabBarController-iAds. The only issue I have is on the very first load of an advert my view gets covered. Once the ad refreshes after 30 seconds the view resizes just fine.
I'm using the following code:
- (void)layoutBanner
{
float height = 0.0;
ADBannerView *_banner = (ADBannerView *)[self.view viewWithTag:12];
CGRect bounds = [UIScreen mainScreen].bounds;
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
_banner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_banner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
//When compiling against iOS 8 SDK this needs to be height, regardless of the actual device orientation
height = bounds.size.height;
CGSize bannerSize = [ADBannerView sizeFromBannerContentSizeIdentifier:_banner.currentContentSizeIdentifier];
//Get content view
UIView *_contentView = self.selectedViewController.view;
CGRect contentFrame = _contentView.frame;
CGRect bannerFrame = _banner.frame;
if (_banner.isBannerLoaded) {
if (iOS7) {
contentFrame.size.height = height - bannerSize.height;
bannerFrame.origin.y = contentFrame.size.height - self.tabBar.frame.size.height;
} else {
contentFrame.size.height = height - self.tabBar.frame.size.height - bannerSize.height;
bannerFrame.origin.y = contentFrame.size.height;
}
} else {
if (iOS7) {
contentFrame.size.height = height;
bannerFrame.origin.y = bounds.size.height;
} else {
contentFrame.size.height = height - self.tabBar.frame.size.height;
bannerFrame.origin.y = bounds.size.height;
}
}
[UIView animateWithDuration:0.25 animations:^{
_banner.frame = bannerFrame;
_contentView.frame = contentFrame;
} completion:^(BOOL finished) {
[self.view bringSubviewToFront:_banner];
}];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(#"Did load");
[self layoutBanner];
}
Any ideas?
I managed to fix this issue by playing around with the animation block. I moved the content view line and it resolved the issue
[UIView animateWithDuration:0.25 animations:^{
_banner.frame = bannerFrame;
} completion:^(BOOL finished) {
_contentView.frame = contentFrame;
[self.view bringSubviewToFront:_banner];
}];
I'm not 100% sure, but I suppose the problem is related to:
[self.view bringSubviewToFront:_banner];
The whole animation:
[UIView animateWithDuration:0.25 animations:^{
_banner.frame = bannerFrame;
_contentView.frame = contentFrame;
} completion:^(BOOL finished) {
[self.view bringSubviewToFront:_banner];
}];
is a little strange, because at the completion block you are bringing the banner view to front, so I can suppose that before animation did start - the banner was covered by some other view or views - what is the reason of frame animation if banner view is covered - thus cannot be seen while animation is in progress?
Of course the issue applies only for the first run.
as of iOs8 [[UIScreen mainScreen]bounds] has changed.. previously it would always return portrait (where H > W ) values, regardless of interfaceOrientation, but it now appears to respect interface orientation... (which is not a bad thing, unless you're taking previous behaviour for granted)
Why don't you try CGRectGetMinY(CGRect aRect) ..
eg. (Im assuming from your code the banner goes along the screen bottom, and your TAbBar across the top. (which I think is weird..) )
//once you have calculated bannerFrame
contentFrame.size.height = ( CGRectGetMinY(bannerFrame) - CGRectGetMinY (contentView.frame) );
contentFrame.origin.y = CGRectGetMaxY(self.tabbar.frame);
Do you have any constraints / resizingMasks set? when you load a second ad the view controller's view has already been resized to fit an ad, presumably the first ad is the one trying to change things..
I have a positioning issue of admob for the ipad. The position of the banner is in the middle of the screen when running on ipad. Android and iphone display the banner on the bottom. After debuging CGSize s = [[CCDirector sharedDirector] viewSize]; seems to think its an iphone. Any idea why?I am using this sample
Its a cocos2d project.
AppDelegate.h
#define ADMOB_BANNER_UNIT_ID ((IS_IPAD) ? #"a1526954f69b314" : #"a1526955dc20272" );
#import "GADBannerView.h"
typedef enum _bannerType
{
kBanner_Portrait_Top,
kBanner_Portrait_Bottom,
kBanner_Landscape_Top,
kBanner_Landscape_Bottom,
}CocosBannerType;
#define BANNER_TYPE kBanner_Portrait_Bottom
#interface AppController : CCAppDelegate<GADBannerViewDelegate> {
CocosBannerType mBannerType;
GADBannerView *mBannerView;
float on_x, on_y, off_x, off_y;}
-(void)hideBannerView;
-(void)showBannerView;
#end
AppDelegate.m
#implementation AppController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Configure Cocos2d with the options set in SpriteBuilder
NSString* configPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"Published-iOS"]; // TODO: add support for Published-Android support
configPath = [configPath stringByAppendingPathComponent:#"configCocos2d.plist"];
NSMutableDictionary* cocos2dSetup = [NSMutableDictionary dictionaryWithContentsOfFile:configPath];
// Note: this needs to happen before configureCCFileUtils is called, because we need apportable to correctly setup the screen scale factor.
#ifdef APPORTABLE
if([cocos2dSetup[CCSetupScreenMode] isEqual:CCScreenModeFixed])
[UIScreen mainScreen].currentMode = [UIScreenMode emulatedMode:UIScreenAspectFitEmulationMode];
else
[UIScreen mainScreen].currentMode = [UIScreenMode emulatedMode:UIScreenScaledAspectFitEmulationMode];
#endif
// Configure CCFileUtils to work with SpriteBuilder
[CCBReader configureCCFileUtils];
// Do any extra configuration of Cocos2d here (the example line changes the pixel format for faster rendering, but with less colors)
//[cocos2dSetup setObject:kEAGLColorFormatRGB565 forKey:CCConfigPixelFormat];
[self setupCocos2dWithOptions:cocos2dSetup];
#ifndef APPORTABLE
[[AAGameCenter sharedGameCenter] authenticateLocalUser];
#endif
[self createAdmobAds];
return YES;
}
- (CCScene*) startScene
{
return [CCBReader loadAsScene:#"MainMenuScene"];
}
+ (void)initialize
{
#ifndef APPORTABLE
//configure iRate
[iRate sharedInstance].appStoreID = 87522385224; // Replace this
#endif
}
-(void)createAdmobAds
{
mBannerType = BANNER_TYPE;
if(mBannerType <= kBanner_Portrait_Bottom)
mBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
else
mBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
mBannerView.adUnitID = #"ca-app-pub-885995432323732999994/1885724261";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
mBannerView.rootViewController = self.navController;
[self.navController.view addSubview:mBannerView];
//#ifdef DEBUG
// GADRequest *request = [GADRequest request];
// request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
//#endif
// Initiate a generic request to load it with an ad.
[mBannerView loadRequest:[GADRequest request]];
CGSize s = [[CCDirector sharedDirector] viewSize];
CGRect frame = mBannerView.frame;
off_x = 0.0f;
on_x = 0.0f;
switch (mBannerType)
{
case kBanner_Portrait_Top:
{
off_y = -frame.size.height;
on_y = 0.0f;
}
break;
case kBanner_Portrait_Bottom:
{
off_y = s.height;
on_y = s.height-frame.size.height;
}
break;
case kBanner_Landscape_Top:
{
off_y = -frame.size.height;
on_y = 0.0f;
}
break;
case kBanner_Landscape_Bottom:
{
off_y = s.height;
on_y = s.height-frame.size.height;
}
break;
default:
break;
}
frame.origin.y = off_y;
frame.origin.x = off_x;
mBannerView.frame = frame;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationOptionCurveEaseOut];
frame = mBannerView.frame;
frame.origin.x = on_x;
frame.origin.y = on_y;
mBannerView.frame = frame;
[UIView commitAnimations];
}
-(void)showBannerView
{
if (mBannerView)
{
//banner on bottom
{
CGRect frame = mBannerView.frame;
frame.origin.y = off_y;
frame.origin.x = on_x;
mBannerView.frame = frame;
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationOptionCurveEaseOut
animations:^
{
CGRect frame = mBannerView.frame;
frame.origin.y = on_y;
frame.origin.x = on_x;
mBannerView.frame = frame;
}
completion:^(BOOL finished)
{
}];
}
//Banner on top
// {
// CGRect frame = mBannerView.frame;
// frame.origin.y = -frame.size.height;
// frame.origin.x = off_x;
// mBannerView.frame = frame;
//
// [UIView animateWithDuration:0.5
// delay:0.1
// options: UIViewAnimationCurveEaseOut
// animations:^
// {
// CGRect frame = mBannerView.frame;
// frame.origin.y = 0.0f;
// frame.origin.x = off_x;
// mBannerView.frame = frame;
// }
// completion:^(BOOL finished)
// {
//
//
// }];
// }
}
}
-(void)hideBannerView
{
if (mBannerView)
{
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^
{
CGRect frame = mBannerView.frame;
frame.origin.y = off_y;
frame.origin.x = off_x;
mBannerView.frame = frame;
}
completion:^(BOOL finished)
{
}];
}
}
-(void)dismissAdView
{
if (mBannerView)
{
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^
{
CGSize s = [[CCDirector sharedDirector] viewSize];
CGRect frame = mBannerView.frame;
frame.origin.y = frame.origin.y + frame.size.height ;
frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);
mBannerView.frame = frame;
}
completion:^(BOOL finished)
{
[mBannerView setDelegate:nil];
[mBannerView removeFromSuperview];
mBannerView = nil;
}];
}
}
#end
I had the same situation until I found this. #macgeo your solution does work, I am not sure why but it does revert back the size to the values that work for an ipad device
Additional info: Using SpriteBuilder with produces a content size of (384,512) on a portrait layout with a content scale factor of 4. The content scale factor has no influence in the result of the view positioning as when changing size to
CGRect contentFrame = [CCDirector sharedDirector].view.bounds;
which produces a size of (768,1024) like if it were using a content scale factor of 2, but still the value is 4.
Think problem might be fixed by changing viewSize to view.bounds
//CGSize s = [[CCDirector sharedDirector] viewSize];
CGRect contentFrame = [CCDirector sharedDirector].view.bounds;
And then using contentFrame.size.height for your y positioning. Was having trouble with iAd stuff and that seemed to fix it.
This question already has answers here:
How can I make a UITextField move up when the keyboard is present - on starting to edit?
(98 answers)
Closed 9 years ago.
I have created a form in IOS using scrollview with some text fields. the view looks like this,
When I begin to edit either state or below fields, the keyboard hides that field. like this,
what should i do to see the below fields (i.e., state and below)??
You can try this code
Add following code at top of your viewcontroller.m file
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.8;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 162;
CGFloat animatedDistance;
Inside textFieldShouldBeginEditing
-(BOOL) textFieldShouldBeginEditing:(UITextField*)textField
{
CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];
CGRect viewRect = [self.view.window convertRect:self.view.bounds fromView:self.view];
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator = midline - viewRect.origin.y - MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator = (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION)
* viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
if (heightFraction < 0.0)
{
heightFraction = 0.0;
}
else if (heightFraction > 1.0)
{
heightFraction = 1.0;
}
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown)
{
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
CGRect viewFrame = self.view.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
return YES;
}
Inside textFieldShouldEndEditing
- (BOOL) textFieldShouldEndEditing:(UITextField*)textField
{
CGRect viewFrame = self.view.frame;
viewFrame.origin.y += animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
}
You should definitely search for this in stack-overflow itself, before posting a question. Anyways, you can find the answer here.
Conform to protocol UITextFieldDelegate
Have a BOOL variable moved to signal, whether your view is moved or not.
Then implement the delegate methods.
-(void)textFieldDidBeginEditing:(UITextField *)textField {
if(!moved) {
[self animateViewToPosition:self.view directionUP:YES];
moved = YES;
}
}
-(void)textFieldDidEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
if(moved) {
[self animateViewToPosition:self.view directionUP:NO];
}
moved = NO;
return YES;
}
-(void)animateViewToPosition:(UIView *)viewToMove directionUP:(BOOL)up {
const int movementDistance = -60; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement = (up ? movementDistance : -movementDistance);
[UIView beginAnimations: #"animateTextField" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
viewToMove.frame = CGRectOffset(viewToMove.frame, 0, movement);
[UIView commitAnimations];
}
You need to use TPAvoidingKeyBoard Library into your app your problem is solved..
https://github.com/michaeltyson/TPKeyboardAvoiding
See this link. Download this project and add it into your project.
Then first you have to add scrollview to your view and then all your textfield into that scrollview add that TPAvoidingScrollView To Custom Class.
Your code is good. but you have to change UIScrollView y position instead of height. I have change your code and update. please update this
step 1: In the ViewDidLoad method of your class set up to listen for messages about the keyboard:
// Listen for keyboard appearances and disappearances
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
step 2: up/down your scrollview by implementing selector methods in same class
- (void)keyboardDidShow: (NSNotification *) notif{
//Keyboard becomes visible
scrollView.frame = CGRectMake(scrollView.frame.origin.x,
scrollView.frame.origin.y - 220,
scrollView.frame.size.width,
scrollView.frame.size.height); //move up
}
- (void)keyboardDidHide: (NSNotification *) notif{
//keyboard will hide
scrollView.frame = CGRectMake(scrollView.frame.origin.x,
scrollView.frame.origin.y + 220,
scrollView.frame.size.width,
scrollView.frame.size.height); //move down
}
Try this code
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField==tfLocation)
{
[self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y-50, self.view.frame.size.width, self.view.frame.size.height)];
}
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self.view setFrame:CGRectMake(self.view.frame.origin.x, 0, self.view.frame.size.width, self.view.frame.size.height)];
}
I have the following interface layout on my application:
When I click on a text field (if you lick add tag a new text field is added) I make my view scroll up as to not be obstructed by the keyboard so the user can properly see what he's typing, but the following happens when I do so:
This is the code I use to scroll:
- (void)keyboardWillShow:(NSNotification *)notification {
if (self.keyboardIsShown) {
return;
}
NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [keyboardBoundsValue CGRectValue].size;
NSTimeInterval animationDuration = 0.3;
CGRect frame = self.view.frame;
frame.origin.y -= keyboardSize.height - 94 + self.firstResponder.superview.superview.frame.origin.y;
frame.size.height += keyboardSize.height - 94 + self.firstResponder.superview.superview.frame.origin.y;
[UIView beginAnimations:#"ResizeForKeyboard" context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIView commitAnimations];
self.keyboardIsShown = YES;
}
- (void)keyboardWillHide:(NSNotification *)notification {
NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [keyboardBoundsValue CGRectValue].size;
NSTimeInterval animationDuration = 0.3;
CGRect frame = self.view.frame;
frame.origin.y += keyboardSize.height - 94 + self.firstResponder.superview.superview.frame.origin.y;
frame.size.height -= keyboardSize.height - 94 + self.firstResponder.superview.superview.frame.origin.y;
[UIView beginAnimations:#"ResizeForKeyboard" context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIView commitAnimations];
self.keyboardIsShown = NO;
}
Any idea how I can make the view elements show behind the navbar or disappear or another workaround that would work properly?
A quick way to achieve what you want, would be to have your navigation bar below the "content"-view in your view tree. That way the navigation bar will remain on top. If you add the content dynamically. Make sure you add them as subviews of a view that is behind the navigation bar.
// Edit
As proposed in the comments:
self.view.clipsToBounds = YES;
CGRect frame = self.yourWrappingView.frame;
NSUInteger distanceToMove = 200;
self.yourWrappingView.frame = CGRectMake(frame.origin.x - distanceToMove, frame.origin.y, frame.size.width, frame.size.height);
This should work for you mate :)
Probably you are not using a real UINavigationController. But you should. So you wouldn't have those problems and a correct resizing behaviour. But to solve it in your current architecture:
Make sure the Navigation Bar is the top most object in your nib file / storyboard
add an IBOutlet for your UINavigationBar and if you insert new views dynamically, use [self insertSubview: newView belowSubview: navigationBarOutlet];