gpt4 book ai didi

ios - 如何防止调整 UIView 的大小以适应 ScrollView 的高度(禁用自动调整)?

转载 作者:可可西里 更新时间:2023-11-01 04:44:46 26 4
gpt4 key购买 nike

我正在使用 vfr-reader 库编写一个 PDF 阅读器。为了横向显示两个页面,我将每个页面渲染到它自己的 View 中,然后将这两个 View 添加到容器 View ,然后将容器 View 添加到 ScrollView 。每个 View 的 autoresizingMask 设置为 UIViewAutoresizingNone,contentMode 为 UIViewContentModeRedraw,所有 View 的 autoresizingSubviews 设置为“NO”。

但容器 View 仍然以某种方式自动调整大小以适应 ScrollView 的高度,我不知道这是在哪里发生的。我关心这个是因为,当自动调整容器 View 时,它的宽度变得大于屏幕宽度,我无法通过一次滑动(需要两次滑动)滚动到下两个页面,这很糟糕。我错过了什么?

编辑 如果有帮助,我会添加一些。在 ViewController 中,我创建了一个带有以下选项的 ScrollView :

theScrollView = [[ReaderScrollView alloc] initWithFrame:viewRect];
theScrollView.scrollsToTop = NO;
theScrollView.pagingEnabled = YES;
theScrollView.delaysContentTouches = NO;
theScrollView.showsVerticalScrollIndicator = NO;
theScrollView.showsHorizontalScrollIndicator = NO;
theScrollView.contentMode = UIViewContentModeRedraw;
theScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
theScrollView.backgroundColor = [UIColor clearColor];
theScrollView.userInteractionEnabled = YES;
theScrollView.autoresizesSubviews = NO;
theScrollView.delegate = self;
[self.view addSubview:theScrollView];

当我绘制页面时,我正在向 ScrollView 添加一个 UIView,它是这样启动的:

if ((self = [super initWithFrame:frame]))
{
self.autoresizesSubviews = YES;
self.userInteractionEnabled = YES;
self.contentMode = UIViewContentModeRedraw;
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.backgroundColor = [UIColor clearColor];

theScrollView = [[ReaderScrollView alloc] initWithFrame:self.bounds]; // Not sure about this part - why is the 2nd scroll view added?
// this is the way its done in vfr reader

theScrollView.scrollsToTop = NO;
theScrollView.delaysContentTouches = NO;
theScrollView.showsVerticalScrollIndicator = NO;
theScrollView.showsHorizontalScrollIndicator = NO;
theScrollView.contentMode = UIViewContentModeRedraw;
theScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
theScrollView.backgroundColor = [UIColor clearColor];
theScrollView.userInteractionEnabled = YES;
theScrollView.autoresizesSubviews = NO;
theScrollView.bouncesZoom = YES;
theScrollView.delegate = self;

theContentView = [[ReaderContentPage alloc] initWithURL:fileURL page:page password:phrase landscape:(BOOL)isLandscape position:FALSE];
CGRect viewRect = CGRectZero;
viewRect.size.width = theContentView.bounds.size.width;
viewRect.size.height = theContentView.bounds.size.height;


if( isLandscape){
NSLog(@"Landscape detected in content view");
if (theContentView == NULL)
{
theContentView = [[ReaderContentPage alloc] initWithURL:fileURL page:(page+1) password:phrase landscape:(BOOL)isLandscape position:FALSE];
theContentView2 = NULL;
viewRect.size.width = theContentView.bounds.size.width;
viewRect.size.height = theContentView.bounds.size.height;
} else {
if (page == 1)
theContentView2 = NULL;
else
theContentView2 = [[ReaderContentPage alloc] initWithURL:fileURL page:(page+1) password:phrase landscape:(BOOL)isLandscape position:TRUE];
if (theContentView2 != NULL)
viewRect.size.width = theContentView.bounds.size.width*2;
}

}
if (theContentView != nil) // Must have a valid and initialized content view
{

theContainerView = [[UIView alloc] initWithFrame:viewRect];


theContainerView.autoresizesSubviews = NO;
theContainerView.userInteractionEnabled = NO;
theContainerView.contentMode = UIViewContentModeRedraw;
theContainerView.autoresizingMask = UIViewAutoresizingNone;
theContainerView.backgroundColor = [UIColor whiteColor];


theScrollView.contentSize = theContentView.bounds.size; // Content size same as view size


theScrollView.contentOffset = CGPointMake((0.0f - CONTENT_INSET), (0.0f - CONTENT_INSET));
theScrollView.contentInset = UIEdgeInsetsMake(CONTENT_INSET, CONTENT_INSET, CONTENT_INSET, CONTENT_INSET);

theThumbView = [[ReaderContentThumb alloc] initWithFrame:theContentView.bounds]; // Page thumb view

[theContainerView addSubview:theThumbView]; // Add the thumb view to the container view

[theContainerView addSubview:theContentView]; // Add the content view to the container view

if(( isLandscape) && (theContentView2 != NULL)){
[theContainerView addSubview:theContentView2]; // Add the content view to the container view

}



[theScrollView addSubview:theContainerView]; // Add the container view to the scroll view

[self updateMinimumMaximumZoom]; // Update the minimum and maximum zoom scales

theScrollView.zoomScale = theScrollView.minimumZoomScale; // Zoom to fit
}

[self addSubview:theScrollView]; // Add the scroll view to the parent container view

[theScrollView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:NULL];

self.tag = page; // Tag the view with the page number
}

return self;

ReaderContentPage 是这样创建的:

if ((self = [super initWithFrame:frame]))
{
self.autoresizesSubviews = NO;

self.userInteractionEnabled = NO;
self.clearsContextBeforeDrawing = NO;
self.contentMode = UIViewContentModeRedraw;
self.autoresizingMask = UIViewAutoresizingNone;
self.backgroundColor = [UIColor clearColor];

view = self; // Return self
}

最佳答案

ReaderContentView 类的函数 updateMinimumMaximumZoom 中:

适合屏幕的缩放比例的计算是在单个 View 中完成的,但在横向中,它应该从 ContainerView 中计算。

尝试替换这段代码

CGFloat zoomScale = ZoomScaleThatFits(targetRect.size, theContentView.bounds.size);

CGFloat zoomScale = ZoomScaleThatFits(targetRect.size, theContainerView.bounds.size);

关于ios - 如何防止调整 UIView 的大小以适应 ScrollView 的高度(禁用自动调整)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7900583/

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