SHARE
TWEET

Popup Xib 1

a guest Sep 14th, 2017 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "NewBottlePopView.h"
  2. #import "UIViewController+MJPopupViewController.h"
  3.  
  4. @interface NewBottlePopView() <UITextFieldDelegate>
  5. @property (strong, nonatomic) UIViewController *viewController;
  6. @end
  7. @implementation NewBottlePopView
  8. @synthesize viewController;
  9.  
  10. - (id)initWithFrame:(CGRect)frame
  11. {
  12.     self = [super initWithFrame:frame];
  13.     if (self) {
  14.         // Initialization code
  15.     }
  16.     return self;
  17. }
  18.  
  19. /*
  20. // Only override drawRect: if you perform custom drawing.
  21. // An empty implementation adversely affects performance during animation.
  22. - (void)drawRect:(CGRect)rect
  23. {
  24.     // Drawing code
  25. }
  26. */
  27.  
  28. -(void)showPopUpInViewController:(UIViewController *)controller{
  29.    
  30.     if ([controller class] == [UINavigationController class]) {
  31.         viewController = [(UINavigationController*)controller visibleViewController];
  32.         [viewController setKeepOnTouchOutside:NO];
  33.         [viewController presentPopupView:self animationType:MJPopupViewAnimationSlideBottomBottom];
  34.     }else{
  35.         viewController = controller;
  36.         [viewController setKeepOnTouchOutside:NO];
  37.         [viewController presentPopupView:self animationType:MJPopupViewAnimationSlideBottomBottom];
  38.     }
  39. }
  40.  
  41. - (IBAction)close:(id)sender {
  42.     [viewController dismissPopupViewControllerWithanimationType:MJPopupViewAnimationSlideBottomBottom];
  43. }
  44.  
  45.  
  46. #pragma mark Text Field Delegate
  47. -(void)textFieldDidBeginEditing:(UITextField *)textField {
  48.     NSLog(@"screen width: %f", [[UIScreen mainScreen] applicationFrame].size.width);
  49.     if ([[UIScreen mainScreen] applicationFrame].size.width <= 320)
  50.     {
  51.         //CGFloat newY = -textField.frame.origin.y - self.frame.size.height;
  52.         CGFloat newY = -textField.frame.origin.y + 140;
  53.  
  54.         if (newY >= self.frame.origin.y)
  55.             newY = self.frame.origin.y;
  56.        
  57.         [UIView animateWithDuration:0.3 animations:^{
  58.             self.frame = CGRectMake(self.frame.origin.x,
  59.                                     newY,
  60.                                     self.frame.size.width,
  61.                                     self.frame.size.height);   //resize
  62.         }];
  63.     }
  64. }
  65.  
  66. -(void)textFieldDidEndEditing:(UITextField *)textField {
  67.     if (textField.tag == 202)
  68.     {
  69.         NSError *error;
  70.         NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:@"[^\\d]" options:NSRegularExpressionCaseInsensitive error:&error];
  71.         textField.text = [regex stringByReplacingMatchesInString:textField.text options:0 range:NSMakeRange(0, [textField.text length]) withTemplate:@""];
  72.     }
  73.    
  74.     textField.text = [textField.text uppercaseString];
  75.     [textField resignFirstResponder];
  76. //    [self tapBackground:[self.gestureRecognizers firstObject]];
  77. }
  78.  
  79. -(BOOL)textFieldShouldReturn:(UITextField*)textField;
  80. {
  81.     textField.text = [textField.text uppercaseString];
  82.     NSInteger nextTag = textField.tag + 1;
  83.     // Try to find next responder
  84.     UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
  85.     if (nextResponder) {
  86.         // Found next responder, so set it.
  87.         [nextResponder becomeFirstResponder];
  88.     } else {
  89.         // Not found, so remove keyboard.
  90.         [textField resignFirstResponder];
  91.         [self tapBackground:[self.gestureRecognizers firstObject]];
  92.     }
  93.     return NO; // We do not want UITextField to insert line-breaks.
  94. }
  95.  
  96. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  97. {
  98.     textField.text = [textField.text uppercaseString];
  99.     return YES;
  100. }
  101.  
  102. -(void)tapBackground:(UIGestureRecognizer*)getsure{
  103.     [self endEditing:YES];
  104.    
  105.     [UIView animateWithDuration:0.3 animations:^{
  106.         [self setCenter:viewController.view.center];
  107.     }];
  108. }
  109.  
  110. @end
RAW Paste Data
Top