gpt4 book ai didi

iphone - UIScrollView 不滚动,尽管 contentSize 小于 UIImageView

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

所以我有一个 UIImageView 作为 UIScrollView 的 subview ,我将 contentSize 设置为小于 UIImageView 宽度和高度,但是它不允许我滚动..这是为什么?这是一些代码:

UIImage * image = [UIImage imageWithData:data];
UIImageView * imgView = [[UIImageView alloc] initWithImage:image];
[imgView setUserInteractionEnabled:YES];
//[imgView setContentMode:UIViewContentModeScaleAspectFill];
[imgView setBackgroundColor:[UIColor clearColor]];
[imgView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[imgView setFrame:CGRectMake(0, 0, imgView.frame.size.width, imgView.frame.size.height)];

CGRect imgFrame;
imgFrame.size.width = originalImageSize.width;
imgFrame.size.height = originalImageSize.height;
imgFrame.origin.x = imageOriginPoint.x;
imgFrame.origin.y = imageOriginPoint.y;

UIScrollView * imgScrollView = [[UIScrollView alloc] initWithFrame:imgFrame];
[imgScrollView setScrollEnabled:YES];
[imgScrollView setClipsToBounds:YES];
[imgScrollView addSubview:imgView];
[imgScrollView setBackgroundColor:[UIColor clearColor]];


[imgScrollView setFrame:imgFrame];
[imgScrollView setContentSize:CGSizeMake(200, 200)];

SCROLL VIEW CONTENT SIZE WIDTH IS 200.000000 AND HEIGHT CONTENT SIZE IS 200.000000
UIIMAGE VIEW WIDTH IS 2240.225830 AND HEIGHT IS 2240.225830
SCROLL VIEW FRAME WIDTH IS 768.000000 AND SCROLL VIEW FRAME HEIGHT IS 768.000061

有什么想法吗?

最佳答案

那是因为您的 ScrollView 边界大小大于内容大小。content size需要是image view的实际大小,visible size由frame/bounds设置。我猜您想在 {200, 200} 大小的矩形中滚动图像?试试这个:

        UIScrollView * imgScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; // this is your visible rect
[imgScrollView setScrollEnabled:YES];
[imgScrollView setClipsToBounds:YES];
[imgScrollView addSubview:imgView];
[imgScrollView setBackgroundColor:[UIColor yellowColor]];

[imgScrollView setContentSize:imgFrame.size]; // this is your image view size

关于iphone - UIScrollView 不滚动,尽管 contentSize 小于 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8889696/

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