iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – popover内容视图的额外高度大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我用UITableViewController作为内容视图控制器打开UIPopoverController popover.

Popover具有合适的大小,乍一看它的内容视图调整正确,但如果我尝试在弹出窗口内滚动,它会滚动,但不应该.似乎在 – (void)viewDidAppear(图1,2)之后内容视图变得大约高20 px.
我该怎么做来检查尺寸:

- (void)viewDidAppear:(BOOL)animated
{
    NSLog(@"%@",self.view);
}

输出

Popovers[3016:c07] <UITableView: 0x10b80600; frame = (0 0; 200 66); autoresize = W+H; gestureRecognizers = <NSArray: 0x1004cc20>; layer = <CALayer: 0x1004c4a0>; contentOffset: {0,0}>

此时大小正确,它等于弹出窗口的大小.打开popover后,它的内部大小没有边距为66像素(在标尺应用程序的帮助下测量).因此,它似乎应该完全适合内容视图的大小.但意外的垂直滚动以某种方式出现.

比如,如果我在弹出的高度增加20像素,
[mOptionPopoverController setPopoverContentSize:(CGSizE){200,86}];
而且它的内容视图也增加并且符合预期,没有任何滚动条.唯一的问题是我不需要在popover底部空20 px(图3).

做了一个小测试项目来重现我的问题.这是重要的代码

@implementation ViewController

- (IBACtion)buttonPressed:(id)sender
{
    TableViewController *popoverViewController = [[TableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    UIPopoverController* mOptionPopoverController = [[UIPopoverController alloc] initWithContentViewController:popoverViewController];
    [mOptionPopoverController setPopoverContentSize:(CGSizE){200,66}]; 
    CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
    [mOptionPopoverController presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}

@end

@implementation TableViewController

- (id)initWithStyle:(UITableViewStylE)style
{
    self = [super initWithStyle:style];
    if (self) {
        self.tableView.bounces = NO;
    }
    return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reusEIDentifier:CellIdentifier] autorelease];

    return cell;
}

- (void)viewDidAppear:(BOOL)animated
{
    NSLog(@"%@",self.view);
}

@end

pic.1

pic.2

pic.3

这就是我所期望的:

UPD.

做了进一步的调查.
我使用KVO来跟踪框架的变化.我期待它有助于找到有用的东西.我找到了一些东西,但它没有让事情更清楚.

所以,我添加了[self.view addObserver:self forKeyPath:@“frame”选项:NSKeyValueObservingOptionNew context:nil];在TableViewController的 – (id)initWithStyle:(UITableViewStylE)样式方法中,观察方法

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSLog(@"%@",[object valueForKeyPath:keyPath]);
}

这是输出

2013-05-27 15:52:12.755 Popovers[1547:c07] NSRect: {{0,0},{200,84}}
2013-05-27 15:52:12.756 Popovers[1547:c07] NSRect: {{0,66}}
2013-05-27 15:52:12.759 Popovers[1547:c07] <UITableView: 0x9337600; frame = (0 0; 200 66); autoresize = W+H; gestureRecognizers = <NSArray: 0x8949760>; layer = <CALayer: 0x8944690>; contentOffset: {0,0}>

(最后一个来自 – (void)viewDidAppear:(BOOL)动画).

为什么84?这是84-66 = 18,这些不是我正在寻找的20 px.
此外,在调用tableView数据源方法之前,所有三个观察者方法调用会发生.在构建tableView之前如何知道框架?

(我目前使用的问题太多了@robmayoff tableView.scrollEnabled = NO;来抑制不必要的弹出窗口.)

UPD.
甚至Apple系统打印popover在打印机选择列表中也有20 px和不必要的滚动条.

解决方法

这显然是Apple Bug,因为这个问题在WWDC 2013期间被苹果工程师提出并且没有得到答案.

解决方法

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1f;
}

大佬总结

以上是大佬教程为你收集整理的iphone – popover内容视图的额外高度全部内容,希望文章能够帮你解决iphone – popover内容视图的额外高度所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。