iphone – popover内容视图的额外高度

iphone – popover内容视图的额外高度,第1张

概述我用UITableViewController作为内容视图控制器打开UIPopoverController popover. Popover具有合适的大小,乍一看它的内容视图调整正确,但如果我尝试在d出窗口内滚动,它会滚动,但不应该.似乎在 – (void)viewDidAppear(图1,2)之后内容视图变得大约高20 px. 我该怎么做来检查尺寸: - (void)viewDidAppear: 我用UItableVIEwController作为内容视图控制器打开UIPopoverController popover.

Popover具有合适的大小,乍一看它的内容视图调整正确,但如果我尝试在d出窗口内滚动,它会滚动,但不应该.似乎在 – (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}>

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

比如,如果我在d出的高度增加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;来抑制不必要的d出窗口.)

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

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

解决方法是

- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForFooterInSection:(NSInteger)section{    return 0.1f;}
总结

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1081964.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存