簡體   English   中英

如何在UIViewcontroller(StoryBoard)內部向上移動模式UIView

[英]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; 並連接執行此視圖,如果我還需要執行更多操作以將視圖添加到項目中,我也感到不確定。

提前致謝!!

在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;
}];

另外,如果您願意,可以使用此處列出的其他鍵盤通知。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM