I know that there are several similar questions, but I still didn't find a proper solution. I've just created a test project with a custom view:
@interface CustomView : UIView
//..
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setBackgroundColor:[UIColor redColor]];
}
return self;
}
and View Controller:
- (void)viewDidLoad
{
[super viewDidLoad];
CustomView *cv = [(CustomView *) [CustomView alloc] initWithFrame:self.view.frame];
[self.view addSubview: cv];
}
In the Landscape Mode we can see:
How to fix it? I know about layoutSubviews
, but 1.
it's not called while rotating; 2.
How I can resize a view here?
try to set autoresizingMask.
CustomView *cv = [(CustomView *) [CustomView alloc] initWithFrame:self.view.frame];
cv.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview: cv];
You can also have a look at autolayout
Regards,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.