【发布时间】:2012-11-01 18:09:11
【问题描述】:
所以我看过很多其他关于此的帖子,我想我几乎都试过了。我不希望这是重复的,但我无法解决我的问题。我有这样的设置:
当我到达我的滚动视图控制器时,我可以很好地翻页,但我也可以垂直移动图片。我认为这与 NavigationBar 强制向下滚动 ScrollView 框架有关,但仍将框架设置为全屏大小。如何防止滚动视图视图控制器上的任何垂直滚动?我的 .m 如下:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationController.navigationBarHidden = NO;
i = 0;
_PhotoBundle = [[NSBundle mainBundle] pathsForResourcesOfType:@".jpg"inDirectory:@"Dog_Images"];
_PhotoArray = [[NSMutableArray alloc] initWithCapacity:_PhotoBundle.count];
for (NSString* path in _PhotoBundle)
{
[_PhotoArray addObject:[UIImage imageWithContentsOfFile:path]];
}
for (int x = 0; x < _PhotoArray.count; x++)
{
CGRect frame;
frame.origin.x = self.mainScroll.frame.size.width * x;
frame.origin.y = 0;
frame.size = self.mainScroll.frame.size;
UIImage *nextImg = [[UIImage alloc] init];
nextImg = [_PhotoArray objectAtIndex:x];
UIImageView *nextIV = [[UIImageView alloc] initWithFrame:frame];
[nextIV setImage:nextImg];
[self.mainScroll addSubview:nextIV];
//NSLog(@"Pass %d", x);
}
self.mainScroll.contentSize = CGSizeMake(self.mainScroll.frame.size.width * _PhotoArray.count, self.mainScroll.frame.size.height);
}
非常感谢!!
【问题讨论】:
-
viewDidAppear 中
NSLog(@"self.mainScroll.frame:(%f,%f,%f,%f)", self.mainScroll.frame.origin.x, self.mainScroll.frame.origin.y, self.mainScroll.size.height, self.mainScroll.size.width);的输出是什么?这是您所期望的,还是有所不同? -
ScrollTest[361:c07] self.mainScroll.frame:(0.000000,20.000000,460.000000,320.000000) 那是在我将 contentSize 更改为 1.0 之前
-
有趣的是,当我在替换 1.0 时这样做是一样的:
ScrollTest[418:c07] self.mainScroll.frame:(0.000000,20.000000,460.000000,320.000000) -
有趣...这似乎是机器中的幽灵。很高兴你知道了!
标签: iphone ios xcode uiscrollview scroll