iOS - Moving a UITextField to a Different Position when a UIView Moves

冷暖自知 提交于 2019-12-03 20:35:35

You can animate multiple views at the same time. Your code:

label.text = @"Show View";   
[UIView beginAnimations:@"returnView" context:nil];
[UIView setAnimationDuration:0.5];  
CGRect viewFrame = [subView frame];
viewFrame.origin.y  = -230;
subView.frame = viewFrame; 
subView.alpha = 1.0;
[UIView commitAnimations];

.. can include additional frame manipulations on your UITextField:

label.text = @"Show View";   
[UIView beginAnimations:@"returnView" context:nil];
[UIView setAnimationDuration:0.5];  
CGRect viewFrame = [subView frame];
viewFrame.origin.y  = -230;
subView.frame = viewFrame; 
subView.alpha = 1.0;
// let's move our textField too
CGRect textFieldFrame=textField.frame;
frame.origin.y+=40;
textField.frame=textFieldFrame;
[UIView commitAnimations];

Note that if you're targeting iOS 4.x or later, you can rely on animation blocks:

[UIView animateWithDuration:0.5 animations:^{

    CGRect frame;

    // move our subView to its new position
    frame=subView.frame;
    frame.origin.y=-230;
    subView.frame=frame;
    subView.alpha=1.0;

    // let's move our textField too
    frame=textField.frame;
    frame.origin.y=40;
    textField.frame=frame;

}];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!