SizesClasses,autolayout 的frame设置问题
来源:互联网 发布:java api 中文 在线 编辑:程序博客网 时间:2024/06/15 03:38
今天做多线程的课程代码,是一个进度条显示下载进度。
- (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
- SizesClasses,autolayout 的frame设置问题
- StoryBoard AutoLayout不能获取正确frame的问题
- autolayout 动态的修改Frame
- autolayout之后获取uiview的frame
- iOS 获取autolayout后view的frame
- 关于使用autolayout约束的界面添加子界面frame改变的问题
- iOS Autolayout情况下,ViewController嵌套时,childViewController的Frame异常问题
- Set frame in autolayout
- autolayout和frame
- ios 使用autolayout后获取控件真实的frame
- IOS开发之读取使用AutoLayout约束的控件Frame
- 使用AutoLayout布局适配时,如何提前获得AutoLayout完成适配后的子控件的真实frame
- AutoLayout适配时,如何获得AutoLayout完成适配后的子控件的真实frame
- 使用AutoLayout布局适配时,如何提前获得AutoLayout完成适配后的子控件的真实frame
- 详解Autolayout 设置UITableViewCell 高度问题
- 关于Frame的问题
- 关于frame的问题
- Autolayout---UIScrollView的一些问题
- C# 静态类
- android support 支持包 使用
- ACM —— 1001 Exponentiation
- 排序
- QT编译运行时出现xxx.exe does not exist.
- SizesClasses,autolayout 的frame设置问题
- OC基础:Foundation框架之NSString和NSMutableString
- ZOJ 3710 Friends
- java GUI--day22
- java 大数阶乘代码
- 聊聊并发——深入分析ConcurrentHashMap
- 使用序列化实现对象的拷贝
- 三分钟理解“命令模式”——设计模式轻松掌握
- Android 反编译详细介绍