我有一个UIView以编程方式创建的子类。
我的应用程序中有纵向和横向模式,使用自动布局。
最初UIView使用 设定框架initWithFrame,但当方向更改为横向时, 的CGRect则UIView停留在纵向模式。
如何提醒子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];
}
}
Run Code Online (Sandbox Code Playgroud)