簡體   English   中英

調整UIView的大小並在更改方向時旋轉

[英]Resize UIView and rotate when change orientation

我有一個顯示在屏幕上的viewController,並且使用- (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; }將方向設置為“橫向”。 - (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; }在此viewController的視圖的同一Xib文件中,我有另一個視圖設置在頂部,例如此法線控件。該視圖本身不應旋轉,但是當我改變方向時,我希望此視圖將滑塊旋轉並轉到頂部。

我收到使用[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];更改方向的通知[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

首先,我嘗試使用view.bounds = CGRectMake(0, 0, newWidth, 44);來更改此視圖框架的寬度view.bounds = CGRectMake(0, 0, newWidth, 44); 並使用變換旋轉它,但是在調整寬度后我得到了類似的東西

顯然,我丟失了視圖右側的內容,但我不知道為什么(因為我在界面生成器中施加了一些約束,這些約束告訴標簽保留在視圖右側的權利)

之后,我嘗試縮放視圖,但是卻得到了類似的信息[我不能發布兩個以上的鏈接,但是視圖中的所有內容都會變小(這正是縮放應該執行的操作,但不是我想要的)]。 我希望左右的標簽保持相同的寬度,並且當我調整視圖寬度的大小時,只有滑塊變小。

有人知道我在做什么錯嗎?

謝謝!!

為什么不使用自動布局?

這是一個屏幕截圖,您可以如何為視圖設置自動布局

您應該使用autolayout 為該滑塊提供頂部,前導,尾隨和固定高度限制,它將同時管理縱向和橫向。 希望這會有所幫助:)

暫無
暫無

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

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