gpt4 book ai didi

view - UIPageViewController 改变大小?

转载 作者:行者123 更新时间:2023-12-04 05:33:54 25 4
gpt4 key购买 nike

我在 Xcode 4 中使用基于页面的应用程序模板来加载 PDF 页面并在隐藏的文本框上创建一个 UITextView,以便用户可以写笔记。

到目前为止,我已经完成了所有工作,但是当我添加 UITextView 时,它在横向模式下位于错误的位置(显示 2 页)。

// ModelController.m

- (id)init
{
self = [super init];
if (self) {
NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"My PDF File" ofType:@"pdf"];
NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
self.pageData = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfUrl); // pageData holds the PDF file
}
return self;
}

- (DataViewController *)viewControllerAtIndex:(NSUInteger)index storyboard:(UIStoryboard *)storyboard
{
// Return the data view controller for the given index.
if( CGPDFDocumentGetNumberOfPages( self.pageData ) == 0 || (index >= CGPDFDocumentGetNumberOfPages( self.pageData )))
return nil;

// Create a new view controller and pass suitable data.
DataViewController *dataViewController = [storyboard instantiateViewControllerWithIdentifier:@"DataViewController"];
dataViewController.dataObject = CGPDFDocumentGetPage( self.pageData, index + 1 ); // dataObject holds the page of the PDF file

[dataViewController view]; // make sure the view is loaded so that all subviews can be accessed

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake( 10, 20, 30, 40 )];

textView.layer.borderWidth = 1.0f;
textView.layer.borderColor = [[UIColor grayColor] CGColor];

[dataViewController.dataView addSubview:textView]; // dataView is a subview of dataViewController.view in the storyboard/xib

CGRect viewFrame = dataViewController.dataView.frame; // <- *** THIS IS THE WRONG SIZE IN LANDSCAPE ***
}

这种行为真的让我感到惊讶,因为当我旋转 iPad 时并没有调用 viewControllerAtIndex,所以我无法知道 View 框架的实际大小是多少。我在纵向和横向都获得相同的 View 框架:
# in Xcode console:
po [dataViewController view]

# result in either orientation:
(id) $4 = 0x0015d160 <UIView: 0x15d160; frame = (0 20; 768 1004); autoresize = RM+BM; layer = <CALayer: 0x15d190>>
#

有谁知道我是否应该使用转换来正确定位 UITextView?我担心我可能必须独立存储元素的位置,并在收到 shouldAutorotateToInterfaceOrientation 消息时重新定位它们。

似乎 Apple 可能不正确地实现了 UIPageViewController,但我能找到的只是我仍在尝试找出的部分解决方法:

UIPageViewController and off screen orientation changes

谢谢!

最佳答案

我认为这里的技巧是在您的 中覆盖 viewDidLayoutSubviews数据 View Controller 并管理所有以编程方式插入的非自动调整 View 的大小,因为在那之前您并不真正知道父级将对其 subview 做什么。

-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];

self.textView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}

关于view - UIPageViewController 改变大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12223932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com