我試圖將效果添加到2視圖之間的切換。開關只是旋轉設備。到目前爲止,我可以應用從縱向轉到橫向時的效果,但不能反之亦然。切換視圖與轉換效果
這裏是我的代碼:
-(void)orientationChanged:(NSNotification *)object{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIInterfaceOrientationPortrait)
{
/* If I run with this block, I have a Exc Bad Access Error and can't run, so I put it
under comment
[UIView transitionWithView:self.view duration:1.0
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.view addSubview:self.portraitView];
} completion:NULL];
*/
self.view = self.portraitView;
//[self dismissModalViewControllerAnimated:YES];
}
else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation ==
UIInterfaceOrientationLandscapeRight)
{
[UIView transitionWithView:self.view duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.view addSubview:self.landscapeView];
} completion:NULL];
[self dismissModalViewControllerAnimated:NO];
}
}
這樣從縱向傳遞到風景時,我收到預期的效果,但是當我把設備返回到肖像它不會加載portraitView的landscapeView遺體上。 希望有人能幫助我。
編輯:
我剛編輯我上面的代碼是這樣的:
-(void)orientationChanged:(NSNotification *)object{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIDeviceOrientationPortrait)
{
if (self.isViewLoaded && self.view.window)
{
NSLog(@"Portrait1");
[UIView transitionWithView:self.view duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
NSLog(@"Portrait2");
[self.view.window addSubview:self.portraitView];
} completion:NULL];
[self dismissModalViewControllerAnimated:YES];
}
}
else if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation ==
UIDeviceOrientationLandscapeRight)
{
[UIView transitionWithView:self.view duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.view addSubview:self.landscapeView];
} completion:NULL];
[self dismissModalViewControllerAnimated:NO];
NSLog(@"Landscape");
}
}
而影響正常工作。但是我有一個大問題,那就是當我從橫向切換回縱向時,橫向視圖保持在縱向視圖上。我怎麼能解僱它?
我還沒有嘗試過,但也許它與事實有關,你混淆了UIDeviceOrientation和UIInterfaceOrientation,並且你在第二條if語句中幸運..我無法解釋但訪問錯誤,但;當你在調試第一個if語句時,你碰巧有NSLog()嗎? – Aky 2012-03-18 10:20:44
我不確定要理解你在說什麼:我在[self.view addSubview:self.landscapeView]上出錯了;線。所以我把NSLog放在上面,並在調試窗口中看到它。這是你在說什麼嗎? – Enzoses 2012-03-18 11:48:20
我編輯了我的代碼,可以請看一下嗎? – Enzoses 2012-03-18 12:14:02