Sir*_*iss 2 iphone xcode scroll uiscrollview ios
所以我看到了很多其他的帖子,我想我几乎都试过了.我不希望这是一个重复,但我无法解决我的问题.我有这样的设置:

当我到达我的滚动视图控制器时,我可以翻页很好,但我也可以垂直移动图片.我认为它与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);
}
Run Code Online (Sandbox Code Playgroud)
非常感谢你!!
所以我发现了一篇完美解释它的帖子:
当我改变我的
CGSizeMake(self.mainScroll.frame.size.width * _PhotoArray.count, self.mainScroll.frame.size.height);
Run Code Online (Sandbox Code Playgroud)
至
CGSizeMake(self.mainScroll.frame.size.width * _PhotoArray.count, 1.0);
Run Code Online (Sandbox Code Playgroud)
它使得contentSize不大于边界......我读过的东西,但没有完全理解.我希望这可以帮助那些坚持这个的人......