UIViewController-ActionSheetSimulation.m 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // UIViewController-ActionSheetSimulation.m
  3. // JasonDevelop
  4. //
  5. // Created by Jason Lee on 10/23/14.
  6. // Copyright (c) jasondevelop. All rights reserved.
  7. //
  8. #import "UIViewController-ActionSheetSimulation.h"
  9. @implementation UIViewController (ActionSheetSimulation)
  10. - (UIView *)actionSheetSimulationWithPickerView:(UIView *)pickerView withToolbar:(UIToolbar *)pickerToolbar {
  11. UIView* simulatedActionSheetView = [[UIView alloc] initWithFrame:CGRectMake(0,
  12. 0,
  13. UIScreen.mainScreen.bounds.size.width,
  14. UIScreen.mainScreen.bounds.size.height)];
  15. [simulatedActionSheetView setBackgroundColor:[UIColor clearColor]];
  16. CGFloat pickerViewYpositionHidden = UIScreen.mainScreen.bounds.size.height + pickerToolbar.frame.size.height;
  17. [pickerView setFrame:CGRectMake(pickerView.frame.origin.x,
  18. pickerViewYpositionHidden,
  19. pickerView.frame.size.width,
  20. pickerView.frame.size.height)];
  21. CGRect tr = CGRectMake(pickerToolbar.frame.origin.x,
  22. pickerViewYpositionHidden,
  23. pickerToolbar.frame.size.width,
  24. pickerToolbar.frame.size.height);
  25. [pickerToolbar setFrame:tr];
  26. pickerView.backgroundColor = [UIColor darkTextColor];
  27. [simulatedActionSheetView addSubview:pickerView];
  28. [simulatedActionSheetView addSubview:pickerToolbar];
  29. return simulatedActionSheetView;
  30. }
  31. - (void)showActionSheetSimulation:(UIView *)actionSheetSimulation pickerView:(UIView *)pickerView withToolbar:(UIToolbar *)pickerToolbar {
  32. CGFloat pickerViewYposition = UIScreen.mainScreen.bounds.size.height - pickerView.frame.size.height + UIApplication.sharedApplication.statusBarFrame.size.height;
  33. [UIApplication.sharedApplication.keyWindow ? UIApplication.sharedApplication.keyWindow:UIApplication.sharedApplication.windows[0] addSubview:actionSheetSimulation];
  34. [actionSheetSimulation.superview bringSubviewToFront:actionSheetSimulation];
  35. [UIView animateWithDuration:0.25f
  36. animations:^{
  37. [actionSheetSimulation setBackgroundColor:[[UIColor darkGrayColor] colorWithAlphaComponent:0.5]];
  38. [self.view setTintAdjustmentMode:UIViewTintAdjustmentModeDimmed];
  39. [self.navigationController.navigationBar setTintAdjustmentMode:UIViewTintAdjustmentModeDimmed];
  40. [pickerView setFrame:CGRectMake(pickerView.frame.origin.x,
  41. pickerViewYposition,
  42. pickerView.frame.size.width,
  43. pickerView.frame.size.height)];
  44. CGRect tr = CGRectMake(pickerToolbar.frame.origin.x,
  45. pickerViewYposition,
  46. pickerToolbar.frame.size.width,
  47. pickerToolbar.frame.size.height);
  48. [pickerToolbar setFrame:tr];
  49. }
  50. completion:nil];
  51. }
  52. -(void)dismissActionSheetSimulation:(UIView *)actionSheetSimulation {
  53. [UIView animateWithDuration:0.25f
  54. animations:^{
  55. [actionSheetSimulation setBackgroundColor:[UIColor clearColor]];
  56. [self.view setTintAdjustmentMode:UIViewTintAdjustmentModeNormal];
  57. [self.navigationController.navigationBar setTintAdjustmentMode:UIViewTintAdjustmentModeNormal];
  58. [actionSheetSimulation.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  59. UIView* v = (UIView*)obj;
  60. [v setFrame:CGRectMake(v.frame.origin.x,
  61. UIScreen.mainScreen.bounds.size.height,
  62. v.frame.size.width,
  63. v.frame.size.height)];
  64. }];
  65. }
  66. completion:^(BOOL finished) {
  67. [actionSheetSimulation removeFromSuperview];
  68. }];
  69. }
  70. @end