Ios 如何提供纵向和横向两种不同的视图?
我目前正在使用一款IPhone应用程序,它有一个“时间表”。 在纵向,我希望它有一些自定义的常规表视图!当我把IPhone放在横向视图中时,我想让它变成一个更“时间表”的视图,有表格和行 有可能吗?请参阅苹果的文档 请务必阅读文档,但以下是示例实现中的代码:Ios 如何提供纵向和横向两种不同的视图?,ios,objective-c,xcode,Ios,Objective C,Xcode,我目前正在使用一款IPhone应用程序,它有一个“时间表”。 在纵向,我希望它有一些自定义的常规表视图!当我把IPhone放在横向视图中时,我想让它变成一个更“时间表”的视图,有表格和行 有可能吗?请参阅苹果的文档 请务必阅读文档,但以下是示例实现中的代码: @implementation PortraitViewController - (void)awakeFromNib { isShowingLandscapeView = NO; [[UIDevice currentDev
@implementation PortraitViewController
- (void)awakeFromNib
{
isShowingLandscapeView = NO;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
!isShowingLandscapeView)
{
[self performSegueWithIdentifier:@"DisplayAlternateView" sender:self];
isShowingLandscapeView = YES;
}
else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
isShowingLandscapeView)
{
[self dismissViewControllerAnimated:YES completion:nil];
isShowingLandscapeView = NO;
}
}
答案是肯定的,可以通过以下方法:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){
\\ your timetable customisation goes here
}
}
您还需要:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
试试这个
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}
-(void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation
{
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
//write code for portrait mode
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//write code for landscape mode
}
}
它必须同时在5.1和6.0版本中工作。为什么要在横向视图中更改视图?只需启用项目中的所有方向。它将自动定向。如果我误解了你的问题,请纠正我。我只希望时间表能够在横向旋转,而不是整个应用程序