UITabBarControler解決旋轉問題


在一次開發項目中遇到了播放視頻,播放完視頻回到列表,該列表在 NavigationController 裏面, NavigationController 放在了 UItabBarController 裏面,做旋轉禁止的操作,試了好多方法,在 UIViewController 寫禁止旋轉的方法,在 navigaitonController 類別裏面寫,都沒有很好地餓解決該旋轉的方法,都沒有解決該問題.

後來自定義了 UITabBarController的類別纔算解決了該旋轉的問題, 


#import <UIKit/UIKit.h>


@interface UITabBarController (TabBarRotation)


- (BOOL)shouldAutorotate;


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;


@end


#import "UITabBarController+Rotation.h"


@implementation UITabBarController (TabBarRotation)


- (BOOL)shouldAutorotate {


    return YES;


}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

    return UIInterfaceOrientationPortrait;

}


@end



上面的一個類別可以解決 UITabBarController裏面出現的旋轉的問題,


bo

發佈了56 篇原創文章 · 獲贊 6 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章