第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

支持多種方向的最簡(jiǎn)單方法?當(dāng)應(yīng)用程序處于橫向模式時(shí),如何加載自定義NIB?

支持多種方向的最簡(jiǎn)單方法?當(dāng)應(yīng)用程序處于橫向模式時(shí),如何加載自定義NIB?

iOS
開(kāi)心每一天1111 2019-11-07 10:21:26
我有一個(gè)想要支持多種方向的應(yīng)用程序。我有兩個(gè)要使用的.xib文件myViewController.xib,它們myViewControllerLandscape.xib. myViewController.xib存在于project / Resources中,并且myViewControllerLandscape.xib存在于根項(xiàng)目目錄中。我想做的是使用單獨(dú)的NIB (myViewControllerLandscape.xib)進(jìn)行旋轉(zhuǎn)。我嘗試在viewDidLoad like中檢測(cè)旋轉(zhuǎn):if((self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)) {  NSLog(@"Landscape detected!");  [self initWithNibName:@"myViewControllerLandscape" bundle:nil]; }但是我可以在gdb中看到,當(dāng)應(yīng)用程序在橫向設(shè)備上啟動(dòng)時(shí),這不會(huì)執(zhí)行。NSLog消息不會(huì)觸發(fā)。為什么是這樣?我做錯(cuò)了什么?另外,如果我將initWithNibName函數(shù)調(diào)用顯式放入viewDidLoad方法中,則該nib不會(huì)加載,并繼續(xù)顯示myViewController.xib文件。我的電話怎么了?我應(yīng)該指定捆綁商品嗎?謝謝!
查看完整描述

3 回答

?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

您必須加載一個(gè)視圖,然后檢查方向并在需要時(shí)加載另一個(gè)視圖。shouldAutorotateToInterfaceOrientation:如果要旋轉(zhuǎn),則返回“是”來(lái)檢查方向。


我使用導(dǎo)航控制器來(lái)管理過(guò)渡。如果我具有人像視圖并且設(shè)備旋轉(zhuǎn),則我推動(dòng)風(fēng)景視圖,然后在返回肖像時(shí)彈出風(fēng)景視圖。


編輯:


我應(yīng)該在shouldAutorotateToInterfaceOrientation中為所有方向返回YES,但是在應(yīng)用啟動(dòng)時(shí)會(huì)調(diào)用此方法嗎?您是否將視圖推入此功能?


方向常數(shù)不是您查詢的全局變量,而是系統(tǒng)發(fā)送給控制器的消息的一部分。因此,在加載視圖控制器之前,您無(wú)法輕松檢測(cè)方向。相反,您可以硬接線該應(yīng)用程序,使其以特定的方向(通常是縱向)開(kāi)始,然后立即旋轉(zhuǎn)。(請(qǐng)參閱移動(dòng)Safari。它始終以縱向開(kāi)始,然后旋轉(zhuǎn)為橫向。)


這是我用來(lái)交換人像和風(fēng)景視圖的兩種方法。


所有三個(gè)視圖控制器都具有此方法:


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    // Return YES for supported orientations

    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}

肖像有:


- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {


    if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight) {

        [self.nav pushViewController:rightLVC animated:NO];

    }

    if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) {

        [self.nav pushViewController:leftLVC animated:NO];

    }

}

每個(gè)景觀控制器具有以下功能:


- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {


    if (toInterfaceOrientation==UIInterfaceOrientationPortrait) {

        [self.nav popViewControllerAnimated:NO];

    }

該應(yīng)用程序以縱向啟動(dòng)。如果設(shè)備的方向?yàn)闄M向,則按適當(dāng)?shù)臋M向。當(dāng)設(shè)備旋轉(zhuǎn)回縱向時(shí),它將彈出風(fēng)景。對(duì)于用戶而言,它看起來(lái)像是同一視圖將其自身重組為不同的方向。


查看完整回答
反對(duì) 回復(fù) 2019-11-07
?
森欄

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊

我稍加修改,以允許在肖像或風(fēng)景中初步裝入筆尖


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

? ? if( !nibNameOrNil )? ? ?nibNameOrNil = [self nibNameRotated:[[UIApplication sharedApplication] statusBarOrientation]];

? ? self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

? ? return self;

}


- (NSString*) nibNameRotated:(UIInterfaceOrientation)orientation

{

? ? if( UIInterfaceOrientationIsLandscape(orientation))? ? ?return [NSString stringWithFormat:@"%@-landscape", NSStringFromClass([self class])];

? ? return [NSString stringWithFormat:@"%@", NSStringFromClass([self class])];

}


-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{

? ? NSString *nibname = [self nibNameRotated:toInterfaceOrientation];

? ? [[NSBundle mainBundle] loadNibNamed:nibname owner:self options:nil];

? ? [self viewDidLoad];

}


查看完整回答
反對(duì) 回復(fù) 2019-11-07
  • 3 回答
  • 0 關(guān)注
  • 532 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)