Guest User

Untitled

a guest
Apr 26th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. -(void)showView{
  2. animationOverlay=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 400, 400)];
  3. animationOverlay.translatesAutoresizingMaskIntoConstraints=false;
  4.  
  5. UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
  6. [btn setFrame:CGRectMake(0, 0, 100, 100)];
  7. [btn setTitle:@"Go" forState:UIControlStateNormal];
  8. [btn setTranslatesAutoresizingMaskIntoConstraints:false];
  9.  
  10. [animationOverlay setBackgroundColor:[UIColor redColor]];
  11.  
  12. NSLayoutConstraint *leftConstraint = [NSLayoutConstraint
  13. constraintWithItem:animationOverlay attribute:NSLayoutAttributeLeft
  14. relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
  15. NSLayoutAttributeLeft multiplier:1.0 constant:0];
  16.  
  17. NSLayoutConstraint *rightConstraint = [NSLayoutConstraint
  18. constraintWithItem:animationOverlay attribute:NSLayoutAttributeWidth
  19. relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
  20. NSLayoutAttributeWidth multiplier:1.0 constant:0];
  21.  
  22. NSLayoutConstraint *topConstraint = [NSLayoutConstraint
  23. constraintWithItem:animationOverlay attribute:NSLayoutAttributeTop
  24. relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
  25. NSLayoutAttributeTop multiplier:1.0 constant:0];
  26.  
  27. NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint
  28. constraintWithItem:animationOverlay attribute:NSLayoutAttributeBottom
  29. relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
  30. NSLayoutAttributeBottom multiplier:1.0 constant:0];
  31.  
  32. NSLayoutConstraint *centreXConstraint= [NSLayoutConstraint constraintWithItem:btn
  33. attribute:NSLayoutAttributeCenterX
  34. relatedBy:0
  35. toItem:animationOverlay
  36. attribute:NSLayoutAttributeCenterX
  37. multiplier:1
  38. constant:0];
  39.  
  40. NSLayoutConstraint *centreYConstraint= [NSLayoutConstraint constraintWithItem:btn
  41. attribute:NSLayoutAttributeCenterY
  42. relatedBy:0
  43. toItem:animationOverlay
  44. attribute:NSLayoutAttributeCenterY
  45. multiplier:1
  46. constant:0];
  47.  
  48. [self.view addSubview:animationOverlay];
  49. [self.view addConstraint:leftConstraint];
  50. [self.view addConstraint:rightConstraint];
  51. [self.view addConstraint:topConstraint];
  52. [self.view addConstraint:bottomConstraint];
  53. [animationOverlay addSubview:btn];
  54. [self.view addConstraint:centreXConstraint];
  55. [self.view addConstraint:centreYConstraint];
  56.  
  57. }
  58.  
  59. -(void)hideView{
  60. [animationOverlay removeFromSuperview];
  61. }
Add Comment
Please, Sign In to add comment