SizesClasses,autolayout 的frame设置问题

今天做多线程的课程代码,是一个进度条显示下载进度。

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [[SDImageCache sharedImageCache] clearDisk];



    UIView * progressView = [[UIView alloc] init];
    self.progressView = progressView;
    [self.imageView addSubview:progressView];
    NSLog(@"%f",[UIScreen mainScreen].bounds.size.width);
    NSLog(@"%f",self.imageView.bounds.size.width);
    progressView.backgroundColor = [UIColor redColor];
    CGRect frame =progressView.frame;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://cdn.wall88.com/51b260599c9b026922.jpg"] placeholderImage:nil options:SDWebImageProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        float progress = (float)receivedSize/expectedSize;
        //progressView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width * progress,frame.size.height);
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

    }];

}

进度条是一个uiview,通过改变它的宽度,来达到显示进度。
但是我的进度条超出了ImageView的范围,比它长。
原因是在storyboard 中我设置控制器view是SizesClasses,autolayout
这时候不应该直接设置frame,而应该使用约束。

取消SizesClasses,autolayout 后正常显示。

但是我想知道SizesClasses,autolayout 开着,有没有办法做到呢?

我试着打印self.imageView.bounds.size.width,因为进度条的宽度是按着这个值设置的。在viewdidload中,打印是568,而屏幕只有375
这是因为开了sizeClasses吧。然后在ViewdidAppear和viewDidLayoutSubviews中打印,是343.000000,正常了,说明,在Viewdidload时子View还没有自适应屏幕。

但是我在viewDidLayoutSubviews中设置进度条frame已经没有意义了,因为VIEW刚加载完成,图片就开始下载了。

总结:SizesClasses,autolayout开启后不能用frame,不准确,在viewDidLayoutSubviews后控件的大小应该适应屏幕了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值