最近接手了一個項目,正常情況下使用查看圖片是沒問題的。
用到了 MWPhotoBrowser 這個第三方圖片瀏覽庫。
不過發現了一個問題,就是設備橫屏modal
這MWPhotoBrowser
的時候,發生了圖片位置錯亂。
實在沒辦法,所以想到了一個餿主意。
就是modal
的時候使用代碼把設備強制旋轉回去。
//UIDevice+WJ.h
@interface UIDevice (WJ)
/**
* 強制旋轉設備
* @param 旋轉方向
*/
+ (void)setOrientation:(UIInterfaceOrientation)orientation;
@end
//UIDevice+WJ.m
#import "UIDevice+WJ.h"
@implementation UIDevice (WJ)
//調用私有方法實現
+ (void)setOrientation:(UIInterfaceOrientation)orientation {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[self currentDevice]];
int val = orientation;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
@end
參考:
非常感謝我的朋友 pypy ,根據他的博客解決了我現在的問題。
http://pypy.me/ios-heng-shu-ping-de-liang-chong-shi-xian-fang-an/
根據他所提供的方法簡單的封裝了一個分類。
總結:
不管什么主意,能解決現在的問題都是好主意。
就算是餿主意也好,根據現狀把問題解決了,后續才考慮優化。