简体   繁体   English

UIViewContentModeScaleAspectFit不适用于UIScrollView子视图UIImageView

[英]UIViewContentModeScaleAspectFit not working for UIScrollView subview UIImageView

For hours I've been trying to figure out why the UIScrollView won't display the images from a NSMutableArray . 几个小时以来,我一直试图弄清楚为什么UIScrollView不会显示来自NSMutableArray的图像。

I realized the uiimageview objects are in the subview collection inside the UISCrollview but somehow the UIViewContentModeScaleAspectFit is ignored... How can I fit to scale then? 我意识到uiimageview对象位于UISCrollview内的子视图集合中,但不知何故忽略了UIViewContentModeScaleAspectFit ......我怎样才能适应缩放呢?

please, any tips? 请问,有什么提示吗?

- (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);
}

The frame of self.srcBook might not be set. self.srcBook的框架可能未设置。

For more information read this answer. 有关更多信息,请阅读此答案。 Why am I having to manually set my view's frame in viewDidLoad? 为什么我必须在viewDidLoad中手动设置视图的框架?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从UIScrollView中删除子视图UIImageview - Remove subview UIImageview from UIScrollView 翻转UIScrollView上的SubView不起作用 - Flip SubView on UIScrollView not working UIImageView:结合UIViewContentModeScaleAspectFit和UIViewContentModeBottom - UIImageView: combine UIViewContentModeScaleAspectFit and UIViewContentModeBottom 将触摸手势发送到UIScrollView的UIImageView子视图 - Sending touch gestures to UIImageView subview of UIScrollView 如何从UIScrollView获取活动子视图(UIImageView) - How to get active subview (UIImageView) from UIScrollView 在UIImageview上添加UIPinchGestureRecognizer,UIImageview是UIScrollview的子视图 - Adding UIPinchGestureRecognizer on a UIImageview which is subview of UIScrollview's UIScrollView上的UIImageView上的UIButton(不起作用) - UIButton(not working) on the UIImageView on the UIScrollView 为什么UIViewContentModeScaleScaleAspectFit在UIScrollView内的UIImageView中不起作用? 见所附图片 - Why doesn't UIViewContentModeScaleAspectFit work in a UIImageView inside UIScrollView? See Image attached UIScrollView - 防止UIImageView作为UIScrollView的子视图被拖出屏幕 - UIScrollView - Prevent UIImageView as subview of UIScrollView from being dragged off screen 当contentMode UIViewContentModeScaleAspectFit时,禁用UIImageView调整大小的行为 - Disable UIImageView resizing behavior when contentMode UIViewContentModeScaleAspectFit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM