addSubview修改添加的视图的框架 [英] addSubview modifying the added view's frame

查看:295
本文介绍了addSubview修改添加的视图的框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何提出这个问题,但在这里...



我将一个PDF页面转换成一个视图,并将它添加到一个UIViewController 。工作正常,除了一些PDF文件。



由于某些原因,代码通过不同的路径为某些PDF文件。当从PowerPoint创建PDF时发生。在调用addSubview之后,它将通过一个更改PDF视图框架的路径。我为PDFViewController.view.frame添加了一个观察者,并且跟踪是:

  0  -  [PDFViewController observeValueForKeyPath:ofObject:change:context :] 
1 NSKVONotify
2 - [NSKeyValueObservance observeValueForKeyPath:ofObject:change:context:]
3 NSKVONotify
4 - [NSObject(NSKeyValueObserverNotification)didChangeValueForKey:]
5 _NSSetRectValueAndNotify
6 - [UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]
7 - [UIView(Internal)_didMoveFromWindow:toWindow:]
8 - [UIView(Hierarchy)_postMovedFromSuperview:]
9 - [UIView(Internal)_addSubview:positional:relativeTo:]
10 - [UIView(Hierarchy)addSubview:]
11(预期的其余轨迹)
/ pre>

对于大多数PDF文件,这个工作正常。但对于一些,添加的视图的框架被修改在 [UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] 。原点的y坐标向下移动43像素,高度减少约20%。我找不到任何关于该方法内发生的信息,它似乎是UIViewController的内部。



任何人都知道为什么帧被修改?至少在正确的方向轻推?



提前感谢。



编辑:



现在我很确定它是 [UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] 正在拧紧它。我在PDFViewController中实现了一个空的 -viewDidMoveToWindow:(UIWindow *)shouldAppearOrDisappear:(BOOL)标志方法,错误消失了。但这只是不是一个修复,而是可能导致一个被拒绝的应用程序。 >。



有任何建议/意见的人吗?

解决方案

43px是导航栏的大小。你有吗?


I'm not sure how to ask this question, but here goes...

I am rendering a PDF page into a view and adding it to a UIViewController. Works fine, except for some PDF files.

For some reason, the code goes through a different path for certain PDF files. It happens when the PDF is created from PowerPoint. After the addSubview call, it goes through a path that alters the PDF view's frame. I added an observer for PDFViewController.view.frame and the trace goes:

0 -[PDFViewController observeValueForKeyPath:ofObject:change:context:]
1 NSKVONotify
2 -[NSKeyValueObservance observeValueForKeyPath:ofObject:change:context:]
3 NSKVONotify
4 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:]
5 _NSSetRectValueAndNotify
6 -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]
7 -[UIView(Internal) _didMoveFromWindow:toWindow:]
8 -[UIView(Hierarchy) _postMovedFromSuperview:]
9 -[UIView(Internal) _addSubview:positioned:relativeTo:]
10 -[UIView(Hierarchy) addSubview:]
11 (rest of trace is expected)

For most PDF files, this works ok. But for some, the added view's frame gets modified somewhere in [UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]. The y coordinate of the origin moves down by 43 pixels and the height is decreased by around 20%. I can't find any information about what happens inside that method, it appears to be internal to UIViewController.

Anyone have any idea why the frame is being modified? At least a nudge in the right direction?

Thanks in advance.

EDIT:

Now I'm pretty sure that it is [UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]that is screwing it up. I implemented an empty -viewDidMoveToWindow:(UIWindow *)shouldAppearOrDisappear:(BOOL)flag method in PDFViewController and the bug went away. But this just doesn't look like a fix, but instead may lead to a rejected app. >.<

Anyone with any suggestions/comments?

解决方案

43px is size of navigationbar. Do you have it?

这篇关于addSubview修改添加的视图的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆