简体   繁体   English

如何在UIViewcontroller(StoryBoard)内部向上移动模式UIView

[英]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. 我有一个UIView,拖到Object Library中,位于StoryBoard创建的UIViewcontroller内。

Inside of this UIView, I put two Text Field to grab user name and password, and one button to log in. 在此UIView中,我放置了两个文本字段来获取用户名和密码,并输入一个按钮来登录。

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. 我可以移动整个View Controller,但是找不到仅移动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; 我只是将一个对象库的视图拖到Viewcontroller内,并在.h Viecontroller中创建了一个Outlet-@property(弱,非原子)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 ; 在UIViewController内部查看 ;

You have to subscribe for UIKeyboardWillShowNotification and UIKeyboardWillHideNotification . 您必须订阅UIKeyboardWillShowNotificationUIKeyboardWillHideNotification 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 . 另外,如果您愿意,可以使用此处列出的其他键盘通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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