我正在尝试使用下面的代码在IOS 6中设置可滚动的图库。它运行时没有错误,但滚动视图中没有显示任何内容。
图像在项目中,可以在Xcode中查看。此外,uiscrollview已连接到其IBoutlet。
NS Log语句确认调用了setupImgGallery(并且images数组包含6个项目),然后是showGallery。两者都来自
-(void)setupImgGallery
{
NSLog(@"In setupImgGallery \n");
UIImage *image1 = [UIImage imageNamed:@"1.png"];
UIImage *image2 = [UIImage imageNamed:@"2.png"];
UIImage *image3 = [UIImage imageNamed:@"3.png"];
UIImage *image4 = [UIImage imageNamed:@"4.png"];
UIImage *image5 = [UIImage imageNamed:@"5.png"];
UIImage *image6 = [UIImage imageNamed:@"6.png"];
images = [[NSArray alloc] initWithObjects:image1,image2,image3,image4,image5,image6,nil];
imgScrollView.pagingEnabled = YES;
[imgScrollView setIndicatorStyle:UIScrollViewIndicatorStyleDefault];
NSLog(@"Count is |%d|\n",images.count);
int numberOfViews = 6;
for (int i = 0; i < numberOfViews; i++)
{
CGFloat xOrigin = i * IMAGE_WIDTH;
tmpimageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin,0,IMAGE_WIDTH,IMAGE_WIDTH)];
[tmpimageView setImage:[images objectAtIndex:i]];
[imgScrollView addSubview:tmpimageView];
}
imgScrollView.contentSize = CGSizeMake(numberOfViews * IMAGE_WIDTH, IMAGE_WIDTH);
imgScrollView.scrollEnabled = TRUE;
}
- (void)showGallery
{
NSLog(@"In showGallery \n");
singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
//Default value for cancelsTouchesInView is YES, which will prevent buttons to be clicked
singleTap.cancelsTouchesInView = NO;
[imgScrollView addGestureRecognizer:singleTap];
flipped=FALSE;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[mainView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self setupImgGallery];
[self showGallery];
}