我已经将UIView作为View Controller中的子视图
@property(nonatomic,retain) IBOutlet UIView *subview;
然后我像这样在子视图中添加自定义UIView类,
- (void)showdetail
{
CGRect frameToset = CGRectMake(0, 0, self.subview.frame.size.width,self.subview.frame.size.height) ;
customUIViewPaging *demoView = [[customUIViewPaging alloc] initWithFrame:frameToset];
... // so on
[self.subview addSubview:demoView];
}
在纵向模式下,它可以完美工作,但在横向模式下,我将像这样更新框架,
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[self showdetail];
}
然后在横向和纵向完美工作之后,我从该视图中推入另一个视图,并在回到该视图后美化Pushed视图,然后帧大小没有得到很好的调整(从另一个视图返回时,子视图框架在定向时未更新框架) )
我尝试放入
needsUpdateConstraints
,但似乎不起作用[self.subview needsUpdateConstraints];
Check this example
最佳答案
我不会朝自动布局方向移动,因为当显示视图时,您想要正确的帧...如果您想要正确的宽度而不是称之为-(void)viewDidLayoutSubviews{..}
-(void)viewDidLayoutSubviews{
NSLog(@"%f",self.subview.frame.size.width); //here you get correct width
}
现在另一个问题是,每当屏幕旋转或此方法调用..时,您都在添加子视图,因此最好通过删除以前的视图来防止这种情况...
关于ios - UIView作为 subview 方向框架问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36398160/