简体   繁体   中英

Resize UIView and change subview position simultaneously

I have placed out a UIView with a UIButton as a subview in a ViewController in Interface Builder. I also have a UITextField where I have a action witch is triggered every time I type something in it. When I type something my view is supposed to get higher and the button should move to the bottom of the view. But when I type the first letter in the textfield the view resizes but the button doesn't move. When I type a second letter the button moves. Probably because the view is already resized. My question is how to get this to work simultaneously when typing the first letter in the textfield.

My code:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyPressed:) name:UITextFieldTextDidChangeNotification object:textField];

- (void)keyPressed:(NSNotification*)notification{

    view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 200.0);
    button.frame = CGRectMake(button.frame.origin.x, (view.frame.size.height-button.frame.size.height), button.frame.size.width, button.frame.size.height);

}

try to implement this method:

-(void)textFieldDidBeginEditing:(UITextField *)textField
{ 
 // put your action here 
}

Solved it by putting the button at the bottom of the view. Then when I resized the view the button followed along by staying at the bottom. I didn't need to programmatically move the button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM