我在拆分视图的主窗格中使用了UISplitViewController一个UITabBarController带有plain 的内部,在详细信息窗格中使用了一个plain ,它本身包含一个vanilla .UIViewControllerUINavigationControllerUIViewController
我知道Apple建议仅在根级别使用拆分视图,但是我已经看到其他应用程序(例如,亚马逊 - "愿望清单"选项卡)在选项卡中使用拆分视图,因此我确信这是可能的.
我的问题是分割视图的委托方法,即.那些UISplitViewControllerDelegate没有被调用,这阻止我在切换到纵向模式时创建我的弹出菜单.
有问题的方法如下 -
// Called when a button should be added to a toolbar for a hidden view controller
- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc;
// Called when the view is shown again in the split view, invalidating the button and popover controller
- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem;
// Called when the view controller is shown in a popover so …Run Code Online (Sandbox Code Playgroud) 所以我花了一些时间寻找答案,但到目前为止还没有找到任何答案.
我正在尝试从UIInputAccessoryView上的按钮呈现弹出窗口.UIBarButtonItem我想显示popover来自定制视图,所以我可以使用图像.我创建这样的按钮:
buttonImage=[UIImage imageNamed:@"tags.png"];
aButton=[UIButton buttonWithType:UIButtonTypeCustom];
[aButton setImage:buttonImage forState:UIControlStateNormal];
aButton.frame=CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
UIBarButtonItem* compButton2=[[UIBarButtonItem alloc]initWithCustomView:aButton];
[aButton addTarget:self action:@selector(tagIt:) forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
当需要显示popover时,我这样做:
CGRect tRect=[((UIButton*)sender) convertRect:((UIButton*)sender).frame toView:self.notePlainText];
NSLog(@"TagIt tRect: %f %f %f %f", tRect.origin.x, tRect.origin.y, tRect.size.width, tRect.size.height);
[self.popoverController presentPopoverFromRect:tRect inView:self.notePlainText permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Run Code Online (Sandbox Code Playgroud)
但我得到的是:

弹出窗口看起来很好,但是它应该出现在第一个按钮上时出现在第二个按钮上.
然后我发现了这个问题:UIBarButtonItem带有自定义图像而且没有边框,我想,"啊,如果我从barbuttonitem呈现popover而不是这样做,它可能会更好.代码子类UIBarButtonItem为了有一个带图像的按钮,而不是文本,并在调用动作时正确表示barbuttonitem.这允许我使用... presentPopoverFromBarButtonItem ...
所以我在上述问题的第二个答案中尝试了代码,并得到了更好的结果.弹出按钮指向我想要的按钮,但如果设备的方向不是纵向,底部有按钮,则弹出窗口显示方向错误:

最后,我将指出我在程序中的其他地方有其他条形按钮项目,这些项目不在UIInputAccessoryViews中,而且没有问题.它似乎只发生在输入附件视图中.
这就是:隐藏和显示键盘似乎使这项工作更好一点.查看按钮的框架(CGRect)数据,它不会在旋转之间发生变化,除非它被隐藏并带回.这是一个错误吗?
那么..我的问题是:从ui附件视图中嵌入的条形按钮项目呈现弹出窗口的首选,最佳实践方法是什么?
非常感谢你.
cocoa-touch uibarbuttonitem uipopovercontroller uiinterfaceorientation ios
这是一个比任何事情更多的观察,因为我似乎找到了一个解决方法......
当它在一个已被推送到UINavigationController堆栈的控制器中时,下面的代码无法工作.在这种情况下[UIDevice currentDevice].orientation一直回归UIDeviceOrientationUnknown.
-(void)layoutAccordingToOrientation {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
NSLog(@"layoutAccordingToOrientation/orientation==%i", orientation);
if (UIInterfaceOrientationIsLandscape(orientation)) {
:
_detailToolbar.frame = CGRectMake(0, 660, 1024, 44);
} else {
:
_detailToolbar.frame = CGRectMake(0, 916, 768, 44);
}
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self layoutAccordingToOrientation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Run Code Online (Sandbox Code Playgroud)
以下调用已取得:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
Run Code Online (Sandbox Code Playgroud)
要解决这个UIDeviceOrientationUnknown问题,我现在使用以下代码:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
etc.
} else {
etc.
}
Run Code Online (Sandbox Code Playgroud)
......每次都有效.
尽管如此,我仍然不明白为什么第一个变体在推送视图控制器的上下文中不起作用.想法有人吗?这只是一个错误吗?
iphone uinavigationcontroller uiinterfaceorientation uideviceorientation
我在MSNavigationPaneViewController 这里使用并且轮换工作.我已经覆盖了我的根中的旋转方法UINavigationController
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.topViewController != nil) {
return [appDelegate.topViewController supportedInterfaceOrientations];
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.topViewController != nil) {
return [appDelegate.topViewController preferredInterfaceOrientationForPresentation];
} else {
return UIInterfaceOrientationPortrait;
}
}
Run Code Online (Sandbox Code Playgroud)
我推动MSNavigationPaneViewController使用presentViewController: animated:completion:,我有旋转工作,所以某些视图可以有不同的方向.问题是,每个具有不同方向的视图都需要用户倾斜手机以更改其锁定在正确方向上的方向.我已经完成了大量的阅读以使其工作,似乎我需要preferredInterfaceOrientationForPresentation在每个视图加载之前触发,但它不会触发.我认为它没有触发,因为MSNavigationPaneViewController它没有改变使用的视图控制器presentViewController.这是用于MSNavigationPaneViewController更改视图的代码
- (void)setPaneViewController:(UIViewController *)paneViewController
{
if (_paneViewController == …Run Code Online (Sandbox Code Playgroud) 尽我所能,我无法解决iOS7 iPhone应用程序的UISegmentedControl错误.
当我创建分段控件时,我使用此代码:
NSArray *segmentedControlItemArray = [NSArray arrayWithObjects: @"Nominal:\n27 inch", @"Actual:\n700c x 23mm", @"Actual:\n700c x 20mm", nil];
_wheelDiameterSegmentedControl = [[UISegmentedControl alloc] initWithItems:segmentedControlItemArray];
_wheelDiameterSegmentedControl.frame = CGRectMake(0, 102, 290, 50);
_wheelDiameterSegmentedControl.selectedSegmentIndex = 0;
_wheelDiameterSegmentedControl.tintColor = [UIColor colorWithRed:0.35 green:0.4 blue:0.9 alpha:1.0];
for (id segment in [_wheelDiameterSegmentedControl subviews]) {
for (id label in [segment subviews]) {
if ([label isKindOfClass:[UILabel class]]) {
UILabel *titleLabel = (UILabel *) label;
titleLabel.numberOfLines = 0;
}
}
}
[_wheelDiameterSegmentedControl addTarget:self
action:@selector(pickOne:)
forControlEvents:UIControlEventValueChanged];
[_wheelDiameterMenuContainer addSubview:_wheelDiameterSegmentedControl];
Run Code Online (Sandbox Code Playgroud)
可悲的是,我无法发布图像,或者我会向您展示我想要的控件:UISegmented Control中的每个段都有两行文本,换行符正是我要求它的位置.
但是,在旋转时,我想保持分段控件的全宽度,并且换行在宽段中看起来很傻.因此,在willAnimateRotationToInterfaceOrientation中,我包含了以下代码,字符串中没有换行符:
[_wheelDiameterSegmentedControl setFrame:CGRectMake(0, …Run Code Online (Sandbox Code Playgroud) 我的应用程序是一个UITabBarController - > UINavigationController - > UITableViewController - > UIViewController.
我想做两件事:
防止我的tableview旋转,我希望它始终保持纵向.
FORCE&允许我的UIViewcontroller旋转landscapeleft.
我知道的:
据我所知,层次结构顶部的viewcontroller控制旋转.这将是我的UITabBarController?或者更确切地说,它唯一的viewcontroller将在objectIndex:0?
我的项目设置允许纵向,LL和LR旋转.我认为这是我需要遵循的模式,以解决这个问题,允许顶层的ALL旋转,然后单独控制每个vc,对吗?
这是我迄今为止在SO中找到的.
因此,对于我的顶级层次结构,我将项目设置设置为允许旋转到Portrait,LL和LR.
然后在我不想旋转的tableviewcontroller中:
-(BOOL)shouldAutorotate{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
最后在我想要旋转的uiviewcontroller中:
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(BOOL)shouldAutorotate{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.我可以向任何方向旋转.当我到达我的uvc时,我也不知道如何强制旋转LL,这是从我的tablevc的模态segue中调用的.
任何帮助理解这个烂摊子将不胜感激:)
即使我改变了方向,也可以在iOS6下正常工作

iOS7正常工作如果我不改变方向

方向变化iOS7时显示错误.*

我正在以UITextField编程方式创建,它与<iOS7一起正常工作,
使用iOS7及更高版本,当我更改方向时,UITextField光标位置会发生变化.有什么问题?这是iOS的错误吗?
UITextField你看到的圆角UITextField只是,我只是通过设置角落使其圆润UITextField.
我设置了左右视图UITextField.同样在方向改变方法中,我甚至没有接触到它UITextField.
更新:
我发现UIFieldEditor子视图中有contentOffset的变化UITextField
- (void)resizeUITextFieldInsideUITextFieldWithOffset:(CGFloat)y {
for(id subview in [txtSearch subviews]) {
if([subview isKindOfClass:[UIScrollView class]]) {
UIScrollView *textField = (UIScrollView *)subview;
[textField setContentOffset:CGPointMake(0, y)];
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在方向上使用上面的代码修复它,但是当我再次键入时再次出现相同的问题.
我遇到了collectionView项目大小的问题.我想在纵向模式中显示3个项目,在横向模式下显示6个项目.我已经设置了像这样的-layoutSubviews:
- (void)layoutSubviews {
[super layoutSubviews];
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown)) {
//Portrait orientation
self.flowLayoutPortrait.itemSize = CGSizeMake(106, 106);
} else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight)) {
//Landscape orientation
self.flowLayoutPortrait.itemSize = CGSizeMake(93, 93);
}
[self.collectionView.collectionViewLayout invalidateLayout];
}
Run Code Online (Sandbox Code Playgroud)
但是单元格大小不会更新,它对于两个方向始终保持不变.如果我创建2个flowLayouts并使用:
[self.collectionView setCollectionViewLayout:self.flowLayoutLandscape];
Run Code Online (Sandbox Code Playgroud)
一切正常,但我真的不喜欢它们是如何改变的.动画真的很糟糕.而且因为itemSize是唯一需要更新的属性,所以使用1布局似乎是最佳选择.
如何告诉collectionView更新布局?
我的应用程序和iOS 8.3存在很大问题.我有很多崩溃,总是出现同样的错误:
由于未捕获的异常'UIApplicationInvalidInterfaceOrientation'而终止应用程序,原因:'支持的方向与应用程序没有共同的方向,并且[... shouldAutorotate]返回YES
当"......"是很多班级时.一个特殊的问题是类UIAlertView,我在iOS 8.3中遇到UIAlertView崩溃的同样问题, 但我无法解析子类UIAlertView(Apple说UIAlertView类打算按原样使用,不支持子类化)或使用UIAlertController.你能帮助我吗?
我正在尝试实现Instagram视频裁剪功能.为此,我需要获得正确的视频方向,我将以MPMoviePlayerController正确的宽高比布局我的视图,然后用户将能够平移视频并显示方形视频将在动作中被裁剪.
我在获取正确的视频方向时遇到问题.我正在使用以下代码
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:fileUrl options:nil];
NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *track = [tracks objectAtIndex:0];
UIInterfaceOrientation orientation =[self orientationForTrack:track];
// method to get orientation
- (UIInterfaceOrientation)orientationForTrack:(AVAssetTrack *)videoTrack
{
CGSize size = [videoTrack naturalSize];
CGAffineTransform txf = [videoTrack preferredTransform];
if (size.width == txf.tx && size.height == txf.ty)
return UIInterfaceOrientationLandscapeRight;
else if (txf.tx == 0 && txf.ty == 0)
return UIInterfaceOrientationLandscapeLeft;
else if (txf.tx == 0 && txf.ty == size.width)
return UIInterfaceOrientationPortraitUpsideDown;
else
return UIInterfaceOrientationUnknown; …Run Code Online (Sandbox Code Playgroud) video objective-c mpmovieplayercontroller uiinterfaceorientation ios
ios ×6
objective-c ×3
cocoa-touch ×2
iphone ×2
ios7 ×1
ipad ×1
orientation ×1
uilabel ×1
uitextfield ×1
video ×1