Pages

Showing posts with label Move. Show all posts
Showing posts with label Move. Show all posts

Tuesday, October 8, 2013

Move NavigationController for iOS7

Converting iOS 6 app to iOS 7 there is a problem with top navigation for iOS 7. So i found a solution for this. 

Note: Although there are a lot of solutions for this like delta updating in NIB file. but i found this useful and applied in my current project as well.

It should be added in AppDeletegate Class and in didFinishLaunchingWithOptions function before return YES;

    CGRect aRect = self.navigationController.view.frame;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
        aRect.origin.y = 20.0f;
        aRect.size.height -= aRect.origin.y;
    }
    else
    {
        aRect.origin.y = 0.0;
    }
    self.navigationController.view.frame = aRect;
    [self.window setBackgroundColor:[UIColor whiteColor]];

Tuesday, August 13, 2013

Move View while keyboard appears

There are some cases, when you want to type in UITextField and also want to show that in screen. But keyboard hides your UITextField. You can use the following code for this


-(void)setViewMovedUp:(BOOL)movedUp
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3]; // if you want to slide up the view
    
    CGRect rect = self.completeSingleView.frame;
    if (movedUp)
    {
        rect.origin.y -= kOFFSET_FOR_KEYBOARD;
        rect.size.height += kOFFSET_FOR_KEYBOARD;
    }
    else
    {
        rect.origin.y += kOFFSET_FOR_KEYBOARD;
        rect.size.height -= kOFFSET_FOR_KEYBOARD;
    }
    self.completeSingleView.frame = rect;
    
    [UIView commitAnimations];
}

Now How to Use this

First of all set the <UITextFieldDelegrate> in class ".h" file and set UITextField delegate to self, Like if we have some textfield with name "loginID" then set the delegate to self like below

loginID.delegate = self;

Now use the below code, which call the upper function 

-(void)textFieldDidEndEditing:(UITextField *)sender
{
    if  (self.completeSingleView.frame.origin.y < 0)
        [self setViewMovedUp:NO];
}
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
    if  (self.completeSingleView.frame.origin.y >= 0)
        [self setViewMovedUp:YES];
}