我试图将效果添加到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