iPhone SDK ScrollView 显示额外空间

标签 iphone uiscrollview

我有一个 ScrollView ,其中有一个显示 960x960 图像的 ImageView ,但它滚动到接近 4 倍的图像。我尝试记录所有可能 View 的宽度,所有内容都声称它是 960x960(或更小,我想我记录了屏幕宽度一次......?)

我需要此图像在图像的右下角停止滚动,而不是进入死区。任何帮助将不胜感激。

哎呀,即使告诉我比我的scrollView.contentSize大的对象的名称是什么也会让我走上正确的轨道......

//Test-Image is just a 960 by 960 image that's numbered around the edges 1-10 so you can tell if it's being moved
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Test-Image.png"]];
self.imageView = tempImageView;
[tempImageView release];

scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);

//Tested with this, results the same.
//[scrollView setContentSize:CGSizeMake(960, 960)];

NSLog(@"What is my scrollView's height attribute?...%f", scrollView.contentSize.height);
// Returns 960
NSLog(@"What is in scrollView's width attribute?...%f", scrollView.contentSize.width);
// Returns 960

scrollView.contentOffset = CGPointMake(480, 480);

scrollView.maximumZoomScale = 8.0;
scrollView.minimumZoomScale = 0.25;
// Commenting clipsToBounds out doesn't seem to have any effect
scrollView.clipsToBounds = YES;
scrollView.delegate = self;

[scrollView addSubview:imageView];

最佳答案

不幸的是,我没有具体的答案。

  • 引用。尝试 [scrollView addSubview: self.imageView];而不是 [...addSubview: imageView];

  • 内容大小。尝试添加 ImageView 后设置内容大小。
    [scrollView setContentSize: CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];

  • 代表。您是否使用并设置了 ScrollView 的委托(delegate)属性(oIWScroll.delegate = self;)?

  • 剪辑。应该没关系。

  • ScrollView 框架。确保 ScrollView 的框架等于或小于 [UIScreen mainScreen].applicationFrame。

  • 框架。当我遇到与您描述的情况类似的情况时,我所做的一件事是创建一个容器 UIView,将其添加到 ScrollView 并将对象填充到容器 View 中。但您确实不必对一张图像执行此操作。
    我还设置了 contentMode = UIViewContentModeTop。

希望这些建议对您有所帮助。

关于iPhone SDK ScrollView 显示额外空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2337364/

相关文章:

iphone - 有没有办法完全断开应用程序与 iCloud 的连接?

ios - ObjC-以编程方式将标签添加到UIScrollView

ios - 如何在 ScrollView Swift 中为图像变化设置动画

iOS 未经授权允许不同的屏幕方向

iphone - 截断 TTStyledTextLabel 中的文本

iphone - 是否可以为备用网址添加书签

ios - UIScrollView 在缩放时具有减速动画(与滚动相同的行为)

objective-c - 创建全向 ScrollView

ios - 父 View 边界的最小 x 值?

iphone - 如何在 iPhone 应用程序中使用 Shoutcast?