我有2 scrollviews
和1 imageview
。
现在在主要内部scrollview
我还有另一个scrollview
,在此scrollview
我有图像。
所以,我的主Scrollview
名为“ScrollView
”,而子scrollview
名为“scrView
”
现在我可以在“scrView
”中添加“ScrollView
”,但我无法在“scrView
”中看到我的图片
我的编码如下:
int numberOfPages = 10;
[scrollView setPagingEnabled:YES];
[scrollView setContentSize:CGSizeMake(scrollView.bounds.size.width * numberOfPages, scrollView.bounds.size.height)];
CGRect pageFrame;
CGRect imageFrame;
UIImageView *imageView;
for(int i=0; i < numberOfPages; i++)
{
pageFrame = CGRectMake(i * scrollView.bounds.size.width+50, 0.0f, scrollView.bounds.size.width-100, scrollView.bounds.size.height);
UIScrollView *scrView = [[UIScrollView alloc] init];
imageFrame = CGRectMake(i * scrView.bounds.size.width, 0.0f, scrView.bounds.size.width, scrView.bounds.size.height);
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image1.jpg"]];
[scrView setFrame:pageFrame];
[imageView setFrame:imageFrame];
[scrView setBackgroundColor:[UIColor redColor]];
[scrollView addSubview:scrView];
[scrView addSubview:imageView];
[imageView release];
}
如果您查看代码,我已将imageView
添加为subView
scrView
,但我无法在模拟器中看到图像。
问题是什么?
与我分享你的想法。
感谢...
答案 0 :(得分:2)
这是有用的尝试此代码。问题在于您的imageview框架
int numberOfPages = 10;
[scrollView setPagingEnabled:YES];
[scrollView setContentSize:CGSizeMake(scrollView.bounds.size.width * numberOfPages, scrollView.bounds.size.height)];
CGRect pageFrame;
CGRect imageFrame;
UIImageView *imageView;
for(int i=0; i < numberOfPages; i++)
{
pageFrame = CGRectMake(i * scrollView.bounds.size.width+50, 0.0f, scrollView.bounds.size.width-100, scrollView.bounds.size.height);
UIScrollView *scrView = [[UIScrollView alloc] initWithFrame:pageFrame];
imageFrame = CGRectMake(0.0, 0.0f, scrView.bounds.size.width, scrView.bounds.size.height);
imageView = [[UIImageView alloc] initWithFrame:imageFrame];
imageView.image=[UIImage imageNamed:@"image1.jpg"];
// [scrView setFrame:pageFrame];
[scrView setBackgroundColor:[UIColor redColor]];
[scrView addSubview:imageView];
[scrollView addSubview:scrView];
[imageView release];
}
答案 1 :(得分:0)
将背景颜色设置为 imageView 。然后记录并检查scrView&amp; imageFrame 帧。还可以使用 bringSubviewToFront:
属性。
for(int i=0; i < numberOfPages; i++)
{
UIScrollView *scrView = [[UIScrollView alloc] init];
[scrView setBackgroundColor:[UIColor redColor]];
pageFrame = CGRectMake(i * scrollView.bounds.size.width+50, 0.0f, scrollView.bounds.size.width-100, scrollView.bounds.size.height);
imageFrame = CGRectMake(i * scrView.bounds.size.width, 0.0f, scrView.bounds.size.width, scrView.bounds.size.height);
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image1.jpg"]];
[scrView setFrame:pageFrame];
[imageView setFrame:imageFrame];
[imageView setBackgroundColor:[UIColor blueColor]]
[scrView addSubview:imageView];
[scrView bringSubviewToFront:imageView];
[imageView release];
[scrollView addSubview:scrView];
[scrollView bringSubviewToFront:scrView];
}
答案 2 :(得分:0)
尝试从您的代码配对设置这样..
[scrView setBackgroundColor:[UIColor clearColor]];
[scrView addSubview:imageView]; /// first add imageview and then scrview (screen view) to scrollview
[scrollView addSubview:scrView];