如何向上移动UIViewcontroller(StoryBoard)中的模态UIView

我有一个UIView,被ObjectBar拖拽到一个由StoryBoard创建的UIViewcontroller中。

在这个UIView的内部,我把两个文本字段来抓取用户名和密码,以及一个按钮来登录。

键盘出现时,如何才能移动此视图? 我可以移动整个视图控制器,但我找不到只移动视图的解决方案。

我只是拖动一个视图的对象库,在我的ViewController中,并创建一个Outlet在.h Viecontroller - @属性(弱,非原子)IBOutlet UIView * contentView; 并连接做这个视图,我也怀疑如果我需要做更多的东西来添加视图到项目。

提前致谢!!

查看里面的UIViewController;


您必须订阅UIKeyboardWillShowNotificationUIKeyboardWillHideNotification 。 然后在出现键盘时向上移动模式视图,在键盘隐藏时向下移动。

然后向上或向下动画模式查看是否显示或隐藏键盘:

提升:

[UIView animateWithDuration:ANIMATION_DURATION animations:^{
    CGRect currentFrame = modalView.frame;
    currentFrame.origin.y -= VIEW_FRAME_OFFSET;
    modalView.frame = currentFrame;
}];

下移:

[UIView animateWithDuration:ANIMATION_DURATION animations:^{
    CGRect currentFrame = modalView.frame;
    currentFrame.origin.y += VIEW_FRAME_OFFSET;
    modalView.frame = currentFrame;
}];

此外,如果您想要,您可以使用此处列出的其他键盘通知。

链接地址: http://www.djcxy.com/p/87759.html

上一篇: How to move up a modal UIView inside of a UIViewcontroller (StoryBoard)

下一篇: Subclass of UIViewController is released immediately