I have added my own custom uiview to self.view. As we can't set constraints in storyboard in this scenario, i tried to add programatically.
Followed this How to Create layout constraints programmatically.
I am using below code.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[customView setNeedsUpdateConstraints];
}
-(void)updateViewConstraints
{
UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
[self.view addConstraints:@[
//view1 constraints
[NSLayoutConstraint constraintWithItem:customView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:padding.top],
[NSLayoutConstraint constraintWithItem:customView
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:padding.left],
[NSLayoutConstraint constraintWithItem:customView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:-padding.bottom],
[NSLayoutConstraint constraintWithItem:customView
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeRight
multiplier:1
constant:-padding.right],
]];
}
I am calling [self updateViewConstraints]
from viewDidLoad
,but still i am getting half view in landscape.
Any idea on this. Thanks in Advance.