UIViewContentModeScaleAspectFit不适用于UIScrollView子视图UIImageView

时间:2013-01-12 03:42:49

标签: iphone ios objective-c xcode cocoa-touch

几个小时以来,我一直试图找出UIScrollView无法显示NSMutableArray图片的原因。

我意识到uiimageview对象位于UISCrollview内的子视图集合中,但不知何故忽略了UIViewContentModeScaleAspectFit ......我怎样才能适应缩放呢?

请,任何提示?

- (void)viewDidLoad
{
    [super viewDidLoad];

    BookDalc* bookDalc = [[BookDalc alloc] init];

    NSMutableArray* books = [bookDalc FindByIconID:IconID];

    for(int i = 0;i<books.count;i++)
    {
        CGRect frame;
        frame.origin.x = self.scrBook.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrBook.frame.size;

        UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
        subview.contentMode = UIViewContentModeScaleAspectFit;

        BookEntity *currentModel = [books objectAtIndex:i];
        UIImage *currentImage = [currentModel TheImage];

        subview.image = currentImage;
        [self.scrBook addSubview:subview];
    }
    self.scrBook.contentSize
    = CGSizeMake(self.scrBook.frame.size.width * books.count, self.scrBook.frame.size.height);
}

1 个答案:

答案 0 :(得分:1)

可能未设置self.srcBook的框架。

有关详细信息,请阅读此答案。 Why am I having to manually set my view's frame in viewDidLoad?