How to move up a modal UIView inside of a UIViewcontroller (StoryBoard)
i've got a UIView, dragged of Object Library, inside of a UIViewcontroller created by StoryBoard.
Inside of this UIView, I put two Text Field to grab user name and password, and one button to log in.
How can I move only this View when the keyboard appears? I'm able to move the whole View Controller, but i can't find a solution to move only the View.
I just dragged one View of the Object Library, inside my Viewcontroller and created one Outlet in .h Viecontroller - @property (weak, nonatomic) IBOutlet UIView *contentView; and connected do this View, i'm in doubt too if I need to do something more to add the view to the project.
Thanks in advance!!
View inside UIViewController;
You have to subscribe for UIKeyboardWillShowNotification
and UIKeyboardWillHideNotification
. Then move modal view up when keyboard appears, down when keyboard hides.
Then animate modal view up or down whether keyboard will show or hide:
Move up:
[UIView animateWithDuration:ANIMATION_DURATION animations:^{
CGRect currentFrame = modalView.frame;
currentFrame.origin.y -= VIEW_FRAME_OFFSET;
modalView.frame = currentFrame;
}];
Move down:
[UIView animateWithDuration:ANIMATION_DURATION animations:^{
CGRect currentFrame = modalView.frame;
currentFrame.origin.y += VIEW_FRAME_OFFSET;
modalView.frame = currentFrame;
}];
Also if you want you can use other keyboard notifications listed here.
链接地址: http://www.djcxy.com/p/87760.html上一篇: SubView的背景丢失了