[英]How to move up a modal UIView inside of a UIViewcontroller (StoryBoard)
我有一个UIView,拖到Object Library中,位于StoryBoard创建的UIViewcontroller内。
在此UIView中,我放置了两个文本字段来获取用户名和密码,并输入一个按钮来登录。
当键盘出现时,如何仅移动该视图? 我可以移动整个View Controller,但是找不到仅移动View的解决方案。
我只是将一个对象库的视图拖到Viewcontroller内,并在.h Viecontroller中创建了一个Outlet-@property(弱,非原子)IBOutlet UIView * contentView; 并连接执行此视图,如果我还需要执行更多操作以将视图添加到项目中,我也感到不确定。
提前致谢!!
您必须订阅UIKeyboardWillShowNotification
和UIKeyboardWillHideNotification
。 然后,在出现键盘时向上移动模式视图,在键盘隐藏时向下移动模式视图。
然后向上或向下动画模式视图,以显示或隐藏键盘:
提升:
[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;
}];
另外,如果您愿意,可以使用此处列出的其他键盘通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.