簡而言之,我想在設備變爲橫向時手動旋轉屏幕上的幾個元素,但將實際應用保持爲縱向模式。我怎麼能在後臺取決於這個事件?是否有可能檢測到iPhone在視角方向不變的情況下旋轉了?
0
A
回答
1
您是否嘗試過使用
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
的設備方向這隻能迎合,所以如果你有其他方位禁用。它仍然給正確的值,對於這個曾經向您的設備。您可以其值與(和更多,你可以查看那些https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/index.html#//apple_ref/c/tdef/UIDeviceOrientation)
UIDeviceOrientationPortrait,
UIDeviceOrientationPortraitUpsideDown,
UIDeviceOrientationLandscapeRight,
UIDeviceOrientationLandscapeLeft
我希望這有助於。
編輯:
對於必須添加一個觀察者,檢測設備的方向的情況下被更改。在appdelegate中註冊通知/觀察者,或者在你覺得需要的地方註冊通知/觀察者,並將orientationChanged
方法放在你委派觀察者的類中。 (在大多數情況下可能在同一班)。
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
- (void) orientationChanged:(NSNotification *)note
{
NSLog(@"orientationChanged");
UIDevice * device = note.object;
if(device.orientation == UIDeviceOrientationPortrait)
{
}
// add other else if here
else
{
}
}
請注意,當您添加觀察者時會調用orientationChanged
。只有一次。每次您的設備改變方向後。如果您發現有些混淆,請告訴我。
相關問題
- 1. 在不改變方向的情況下旋轉PDF
- 2. 檢測旋轉輪的方向iPhone
- 3. 是否可以在不使用isNaN的情況下檢測NaN?
- 4. 如何在沒有設備自動旋轉的情況下檢測iPhone上的旋轉?
- 5. 檢測div是否旋轉了30deg
- 6. 檢測iPhone旋轉旋轉?
- 7. 您是否可以在不打開它的情況下檢測到安全.pdf?
- 8. 在不使用三角函數的情況下旋轉矢量
- 9. 是否可以在不使用CSS3的情況下旋轉HTML對象?
- 10. xcode是否可以在不使用代碼的情況下旋轉UI項目?
- 11. 是否有任何情況下DateTimeOffset可能不可靠?
- 12. 是否有可能在不復制的情況下將特徵矩陣變平?
- 13. 是否有可能有很多情況下ngIF在角2模板
- 14. 如何在不使用頁面方向的情況下檢測Windows Phone 8的旋轉?
- 15. 是否可以在沒有Karma的情況下測試Angular?
- 16. Ipad,我可以在不使用視圖控制器的情況下檢測設備旋轉嗎?
- 17. 如何在不改變大小的情況下旋轉QPixmap
- 18. 在不改變大小的情況下旋轉imageView Android
- 19. 我可以在沒有黑條的情況下旋轉UIView嗎?
- 20. 是否可以在不檢測VCS的情況下更改文件行?
- 21. 是否有可能在沒有PHP的情況下創建註冊可能性?
- 22. 如何檢測iPhone在桌子上時是否正在旋轉?
- 23. 如何在不改變位置的情況下旋轉圖像視圖
- 24. iPhone SDK。是否有可能使用AVURLlAsset/AVMutableComposition在AVplayer中旋轉視頻?
- 25. 是否有可能在沒有登錄流的情況下使用量角器測試流量?
- 26. 是否可以在不調用response.sendRedirect(...)方法的情況下發送重定向?
- 27. 是否有可能檢測到Java中是否有類可用?
- 28. 檢測從旋轉270到旋轉90的旋轉變化
- 29. 是否有可能在沒有在Windows上創建用戶的情況下檢查密碼是否有效?
- 30. 是否有可能避免在此情況下
我會給這個鏡頭並報告回來。如果能夠在它發生變化時能夠收到一條消息,那將是很好的,但至少在這一點上我可以調查這個價值。 – BigOmega 2014-11-06 15:11:39
我編輯了我的答案,以便爲正在更改的設備方向添加事件。我最初並沒有注意到你想要一個事件,而不僅僅是一種找到設備當前方向的方法。但看看編輯的答案,看看是否有幫助。 – Abdul91 2014-11-07 06:13:08
工作完美,謝謝! – BigOmega 2014-11-07 16:54:50