0

我正在处理一个分页的 UIScrollView,但它只想在其中显示第一个 UIImageView。我将每个 UIImageView 添加到滚动视图宽度的偏移处,这样应该会创建每个页面。运行时,它说滚动视图是正确的页数,但图像不显示。

任何帮助将非常感激!

int numSlides = NUM_TUTORIAL_SLIDES;
    NSString *fileName;
    UIImageView *slideImageView;
    CGRect slideFrame;

    for (int i = 1; i <= numSlides; i++)
    {
        slideFrame.origin.x = self.tutorialScrollView.frame.size.width * (i-1);
        slideFrame.origin.y = 0;
        slideFrame.size = self.tutorialScrollView.frame.size;

        slideImageView = [[UIImageView alloc] initWithFrame:slideFrame];


        if([[AppManager sharedManager] is4inchScreen])
        {
            fileName = [NSString stringWithFormat:@"Slide%d4in@2x.png", i];
        }

        else
        {
            fileName = [NSString stringWithFormat:@"Slide%d@2x.png", i];
        }

        slideImageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]];

        [self.tutorialScrollView addSubview:slideImageView];

        [slideImageView release];
    }

    self.tutorialScrollView.contentSize = CGSizeMake(self.tutorialScrollView.frame.size.width * numSlides, self.tutorialScrollView.frame.size.height);

    self.tutorialScrollView.delegate = self;
4

2 回答 2

1

也许更改以下代码会有所帮助

    slideImageView.image = [UIImage imageNamed:fileName];
于 2012-09-17T04:01:27.500 回答
0

事实证明,这个问题与滚动视图的圆角有关。

我有这个代码:

//Round header image
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.tutorialScrollView.bounds
                                               byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                                     cornerRadii:CGSizeMake(DEFAULT_CORNER_RADIUS_HEADER, DEFAULT_CORNER_RADIUS_HEADER)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = maskPath.CGPath;
self.tutorialScrollView.layer.mask = maskLayer;

显然这会导致滚动视图出现问题

于 2012-09-18T04:15:04.090 回答