【发布时间】:2017-02-15 04:43:24
【问题描述】:
我有一个以编程方式创建的UIView 子类。
我的应用程序中有纵向和横向模式,它使用自动布局。
最初UIView 框架是使用initWithFrame 设置的,但是当方向更改为横向时,UIView 的CGRect 会停留在纵向模式。
如何提醒UIView 子类更改设备方向上的CGRect?
这是UIView 的初始框架设置代码:
- (id)initWithFrame:(CGRect)frame videoUrl:(NSURL *)videoUrl{
self = [super initWithFrame:frame];
if (self) {
_frame_width = frame.size.width;
int thumbWidth = ceil(frame.size.width*0.05);
_bgView = [[UIControl alloc] initWithFrame:CGRectMake(thumbWidth-BG_VIEW_BORDERS_SIZE, 0, frame.size.width-(thumbWidth*2)+BG_VIEW_BORDERS_SIZE*2, frame.size.height)];
_bgView.layer.borderColor = [UIColor grayColor].CGColor;
_bgView.layer.borderWidth = BG_VIEW_BORDERS_SIZE;
[self addSubview:_bgView];
}
}
【问题讨论】:
-
当app改变方向时,你需要改变view的frame size,对吧?
-
@vaibhav 是的。我必须更改 UIView CGRect。
-
检查我的ans是否适合..
标签: ios objective-c uiview autolayout landscape-portrait