Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void)showView{
- animationOverlay=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 400, 400)];
- animationOverlay.translatesAutoresizingMaskIntoConstraints=false;
- UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
- [btn setFrame:CGRectMake(0, 0, 100, 100)];
- [btn setTitle:@"Go" forState:UIControlStateNormal];
- [btn setTranslatesAutoresizingMaskIntoConstraints:false];
- [animationOverlay setBackgroundColor:[UIColor redColor]];
- NSLayoutConstraint *leftConstraint = [NSLayoutConstraint
- constraintWithItem:animationOverlay attribute:NSLayoutAttributeLeft
- relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
- NSLayoutAttributeLeft multiplier:1.0 constant:0];
- NSLayoutConstraint *rightConstraint = [NSLayoutConstraint
- constraintWithItem:animationOverlay attribute:NSLayoutAttributeWidth
- relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
- NSLayoutAttributeWidth multiplier:1.0 constant:0];
- NSLayoutConstraint *topConstraint = [NSLayoutConstraint
- constraintWithItem:animationOverlay attribute:NSLayoutAttributeTop
- relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
- NSLayoutAttributeTop multiplier:1.0 constant:0];
- NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint
- constraintWithItem:animationOverlay attribute:NSLayoutAttributeBottom
- relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
- NSLayoutAttributeBottom multiplier:1.0 constant:0];
- NSLayoutConstraint *centreXConstraint= [NSLayoutConstraint constraintWithItem:btn
- attribute:NSLayoutAttributeCenterX
- relatedBy:0
- toItem:animationOverlay
- attribute:NSLayoutAttributeCenterX
- multiplier:1
- constant:0];
- NSLayoutConstraint *centreYConstraint= [NSLayoutConstraint constraintWithItem:btn
- attribute:NSLayoutAttributeCenterY
- relatedBy:0
- toItem:animationOverlay
- attribute:NSLayoutAttributeCenterY
- multiplier:1
- constant:0];
- [self.view addSubview:animationOverlay];
- [self.view addConstraint:leftConstraint];
- [self.view addConstraint:rightConstraint];
- [self.view addConstraint:topConstraint];
- [self.view addConstraint:bottomConstraint];
- [animationOverlay addSubview:btn];
- [self.view addConstraint:centreXConstraint];
- [self.view addConstraint:centreYConstraint];
- }
- -(void)hideView{
- [animationOverlay removeFromSuperview];
- }
Add Comment
Please, Sign In to add comment