我需要一个视图控制器(在ipad上)共享两种模式,一种是纵向模式,另一种是横向模式.实际上,我非常想模仿UISplitViewController的功能,但我希望能够使用不作为顶级视图控制器.除了HIG指南之外,我有一个普遍的问题,我认为任何在方向之间切换视图的人都会遇到.
1)为了提供视图之间的平滑过渡,我想在willRotateToInterfaceOrientation:duration中调用我的视图更改(和动画),而不是didRotateToInterfaceOrientation方法.问题是,在这个阶段,视图框架和边界尚未更改为新的视图框架和边界,因此您最终必须手动设置框架,如:
subview.frame = CGRectMake(0,0,320,768);
Run Code Online (Sandbox Code Playgroud)
也许是:而不是更好的东西:
subview.frame = CGRectMake(0,0,320, self.view.frame.height);
Run Code Online (Sandbox Code Playgroud)
2)此外,即使您尝试这样的恶作剧,如果视图自动调整其子视图,您仍然无处可去.如果禁用子视图的自动调整,那么这样的东西甚至不再起作用了:
subview.frame = self.view.frame; //because then you'd have to always specify the exact rect.
Run Code Online (Sandbox Code Playgroud)
有没有人有任何见解可以提供这个?
谢谢!
我正在开发一个仅支持横向定位的应用程序.它使用a UIImagePickerController从库中选择图像和/或视频.应用程序在iOS-5或之前运行良好但在我尝试呈现图像选择器控制器时它会崩溃.它在崩溃后给出以下消息:
*由于未捕获的异常'UIApplicationInvalidInterfaceOrientation'终止应用程序,原因:'支持的方向与应用程序没有共同的方向,并且shouldAutorotate返回YES'
landscape uiimagepickercontroller uiinterfaceorientation ios6
我有一个应用程序,仅用于纵向方向.但是,我不知道如何限制只使用纵向模式,一旦用户颠倒或空间模式,我不希望我的屏幕orinetation相应地改变.
有什么想法怎么做?
花花公子!
需要一些紧急的见解.我的问题是,即使iPhone 4/4S和iPod 4上的测试正常旋转,此代码也是如此:
- (void)initNotifications
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"setFreeOrientation" object:nil];
[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:Nil];
}
-(void)didRotate:(NSNotification*)notification
{
[super rotateTopBars];
[super rotateOptionsBar];
[self rotateControlBar];
[self rotatePlayer];
[super rotateShareLayer];
}
Run Code Online (Sandbox Code Playgroud)
但我正在测试iPod 5并且它不起作用.尝试了一些东西但直到现在都没有运气.
干杯.
我正在使用iOS 6和Xcode 4.5在Storyboard中使用标签栏和一些导航视图控制器开发应用程序
通常应用程序应支持所有界面方向,但我有两个视图,只应支持纵向模式.
所以我将以下代码添加到视图控制器:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
Run Code Online (Sandbox Code Playgroud)
在我在iOS 6上开发的没有故事板和导航视图控制器的其他应用程序上它可以工作,但她不是!:/
我希望有人可以提供帮助,因为我找到了其他一些无用的帖子......
来自德国的问候
Laurenz
编辑:
我也尝试过 - 不行!:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud) 我的应用程序支持所有4方向,我有一个UIViewController这是LandscapeRight.我正在使用UINavigationController推动它UIViewController,我希望它UIViewController只是在UIInterfaceOrientationLandscapeRight,但当我旋转手机时,它切换回其他方向.
-(BOOL)shouldAutorotate{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationLandscapeRight;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeRight;
}
Run Code Online (Sandbox Code Playgroud) iphone objective-c uiviewcontroller uiinterfaceorientation ios
我还没有看到这个问题的明确答案,围绕 iOS 8 的变化有很多噪音,但我想在 iOS 9 上解决这个问题:
\n\n界面方向更改结束后获取回调的正确方法是什么?
\n\n从 iOS 9 开始,didRotateFromInterfaceOrientation:它已被弃用,官方文档告诉我们改用它viewWillTransitionToSize:withTransitionCoordinator。这为我们(通过transitionCoordinator)提供了一种沿着过渡进行动画处理的方法和一个完成块,但没有对过渡的真实 \xe2\x80\x98end\xe2\x80\x99 进行直接回调。
另一种方法是transitionCoordinator,notifyWhenInteractionEndsUsingBlock:但这似乎报告了过渡的交互部分的结束,而不是整个事情。
那么, \xe2\x80\x9cofficial\xe2\x80\x9d 的方法是执行此操作animateAlongsideTransition:completion,并简单地忽略动画选项吗?
我意识到我们仍然可以使用旧的didRotateFromInterfaceOrientation:,但它\xe2\x80\x99s 总是更好地尽可能现代化。
transition uiviewcontroller uiview uiinterfaceorientation ios9
当我改变方向时,我在app中出现了这个错误,我第一次得到它,我以前从未见过这种类型的错误,
我已经搜索了很多关于这个错误,但我没有找到解决这个问题,
在我的应用程序中,我已经编写了NSNotification以进行方向更改
Scroller.m
-(id)initWithFrame:(CGRect)frame {
self=[super initWithFrame:frame];
if (self) {
// Initialization code
scrollView=[UIScrollView new];
pageControl=[UIPageControl new];
scrollView.delegate=self;
scrollView.pagingEnabled=YES;
scrollView.showsHorizontalScrollIndicator=NO;
scrollView.showsVerticalScrollIndicator=NO;
scrollView.translatesAutoresizingMaskIntoConstraints=NO;
pageControl.translatesAutoresizingMaskIntoConstraints=NO;
scrollView.backgroundColor=[UIColor clearColor];
pageControl.backgroundColor=[UIColor darkGrayColor];
[pageControl addTarget:self action:@selector(changePage) forControlEvents:UIControlEventValueChanged];
[self addSubview:scrollView];
[self addSubview:pageControl];
self.pageControl.currentPage = 0;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged)
name:UIDeviceOrientationDidChangeNotification
object:nil];
[self setData];
}
return self;
}
-(void)orientationChanged{
[self updateFrame];
}
-(void)updateFrame{
[self layoutIfNeeded];
CGRect mainFrame=scrollView.frame;
CGRect frame;
.
.
.
.
// COdes for Updating Frame
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
-[NSISLinearExpression orientationChanged:]: unrecognized selector sent to instance …
ios ×6
ios6 ×4
iphone ×3
objective-c ×3
landscape ×2
cocoa-touch ×1
ios5 ×1
ios7 ×1
ios9 ×1
ipod-touch ×1
rotation ×1
transition ×1
uiview ×1