ios - tabbarcontroller + navigation. How to make so that landscape one representation had an orientation -
i created application in has:
viewcontroller
,navigationviewcontroller
,tabbarviewcontroller
.
i have many tabs , respectively many representations. problem when click 1 tab there should portrait orientation. when click following tab should have representation types of orientation.
precisely understand want, start skype application on iphone. first tab can't pass landscape, second can't transfer. if opening chat should possible transfer mode of orientation.
i tried add following code, works in navigationcontroller
not in tabcontroller
.
tabcontroller
:
int test = 0; public override uiinterfaceorientationmask getsupportedinterfaceorientations() { int = 0; foreach (var v in viewcontrollers) { if (v.gettype () == typeof(createcompviewcontroller)) { test = i; break; }i++; } int s = test; test++; if (test==i) return uiinterfaceorientationmask.all; return uiinterfaceorientationmask.portrait; }
thus if make compulsorily without condition, works. understand.
i program on monotouch, without difference. functions identical. if can give example on xcode. makes no difference me.
shouldautorotate, supportedinterfaceorientations, preferredinterfaceorientationforpresentation
the above methods don't called of viewcontroller if inside tabbarcontroller of navigationcontroller. if these methods declared inside tabbarcontroller or navigation controller called. in case viewcontrollers inside navigationcontroller , navigation controllers inside tabbarcontroller.
for solving make class fixedorientationtab, subclass of uitabbarcontroller, , navigation class orientationenablednavigation, subclass of uinavigationcontroller. implemented shouldautorotate, supportedinterfaceorientations, preferredinterfaceorientationforpresentation
methods inside fixedorientationtab , orientationenablednavigation.
orientationenablednavigation.h
#import <uikit/uikit.h> @interface orientationenablednavigation : uinavigationcontroller @end
orientationenablednavigation.m
#import "orientationenablednavigation.h" @interface orientationenablednavigation () @end @implementation orientationenablednavigation - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; // additional setup after loading view. } - (bool)shouldautorotate { return [self.topviewcontroller shouldautorotate]; // return no; } - (nsuinteger)supportedinterfaceorientations { return [self.topviewcontroller supportedinterfaceorientations]; } - (uiinterfaceorientation)preferredinterfaceorientationforpresentation { return [self.topviewcontroller preferredinterfaceorientationforpresentation]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } @end
fixedorientationtab.h
#import <uikit/uikit.h> @interface fixedorientationtab : uitabbarcontroller @end
fixedorientationtab.m
#import "fixedorientationtab.h" @interface fixedorientationtab () @end @implementation fixedorientationtab - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; // additional setup after loading view. } - (bool)shouldautorotate { return [self.selectedviewcontroller shouldautorotate]; // return no; } - (nsuinteger)supportedinterfaceorientations { return [self.selectedviewcontroller supportedinterfaceorientations]; } - (uiinterfaceorientation)preferredinterfaceorientationforpresentation { return [self.selectedviewcontroller preferredinterfaceorientationforpresentation]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } @end
then if want use navigation controller in project use orientationenablednavigation , tabbar fixedorientationtab. after if implement shouldautorotate, supportedinterfaceorientations, preferredinterfaceorientationforpresentation
these method inside viewcontroller called.
hope helps.. :)
Comments
Post a Comment