Advertisement
olcayertas

HMXNewPersonelStep1ViewController.m

Oct 7th, 2013
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "HMXNewPersonelStep1ViewController.h"
  2.    
  3.     @implementation HMXNewPersonelStep1ViewController
  4.    
  5.     - (id)initWithNibName:(NSString *)nibNameOrNil
  6.                    bundle:(NSBundle *)nibBundleOrNil{
  7.         self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  8.        
  9.         if (self) {
  10.    
  11.         }
  12.        
  13.         return self;
  14.     }
  15.    
  16.     - (void)viewDidLoad{
  17.         [super viewDidLoad];
  18.         [self registerForKeyboardNotifications];
  19.         self.gestureRecognizer =
  20.         [[UITapGestureRecognizer alloc]
  21.          initWithTarget:self
  22.          action:@selector(handleSingleTap:)];
  23.         [self.scrollView
  24.          addGestureRecognizer:self.gestureRecognizer];
  25.     }
  26.    
  27.     - (void)didReceiveMemoryWarning{
  28.         [super didReceiveMemoryWarning];
  29.     }
  30.    
  31.     -(void) windowClosed:(NSNotification*)notification {
  32.         [self.scrollView removeGestureRecognizer:self.gestureRecognizer];
  33.     }
  34.    
  35.     - (void)registerForKeyboardNotifications {
  36.         [[NSNotificationCenter defaultCenter]
  37.          addObserver:self
  38.          selector:@selector(keyboardDidShow:)
  39.          name:UIKeyboardDidShowNotification object:nil];
  40.        
  41.         [[NSNotificationCenter defaultCenter]
  42.          addObserver:self
  43.          selector:@selector(keyboardWillHide:)
  44.          name:UIKeyboardWillHideNotification object:nil];
  45.     }
  46.    
  47.     - (void)keyboardDidShow:(NSNotification*)aNotification {
  48.         NSDictionary* info = [aNotification userInfo];
  49.         _kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
  50.     }
  51.    
  52.     - (void)keyboardWillHide:(NSNotification*)aNotification {
  53.         UIEdgeInsets contentInsets = UIEdgeInsetsZero;
  54.         _scrollView.contentInset = contentInsets;
  55.         _scrollView.scrollIndicatorInsets = contentInsets;
  56.     }
  57.    
  58.     - (void)adjustView{
  59.         UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, _kbSize.height, 0.0);
  60.        
  61.         _scrollView.contentInset = contentInsets;
  62.         _scrollView.scrollIndicatorInsets = contentInsets;
  63.        
  64.         CGRect aRect = self.view.frame;
  65.         aRect.size.height -= _kbSize.height;
  66.         CGPoint aPoint =
  67.         CGPointMake(0, _activeField.frame.origin.y+100);
  68.        
  69.         if (!CGRectContainsPoint(aRect, aPoint) ) {
  70.             _oldContentOffset = [_scrollView contentOffset];
  71.             CGPoint scrollPoint =
  72.             CGPointMake(0.0, _activeField.frame.origin.y-_kbSize.height+100);
  73.             [_scrollView setContentOffset:scrollPoint animated:YES];
  74.             NSLog(@"adjusted...", nil);
  75.         }
  76.     }
  77.    
  78.     - (IBAction)textFieldEditingDidBegin:(id)sender {
  79.         _activeField = (UITextField*)sender;
  80.         [self adjustView];
  81.     }
  82.    
  83.     - (IBAction)textFieldEditingDidEnd:(id)sender {
  84.         _activeField = nil;
  85.     }
  86.    
  87.     - (void)handleSingleTap:(UITapGestureRecognizer*)sender {
  88.         if (sender.state == UIGestureRecognizerStateEnded){
  89.             [self backgroundClicked:self];
  90.         }
  91.     }
  92.    
  93.     - (IBAction)backgroundClicked:(id)sender {
  94.         NSLog(@"click!", nil);
  95.         [self.view endEditing:YES];
  96.     }
  97.    
  98.     - (IBAction)backButtonClicked:(id)sender {
  99.         [self.navigationController popViewControllerAnimated:YES];
  100.     }
  101.    
  102.     - (IBAction)nextButtonClicked:(id)sender {
  103.         [self performSegueWithIdentifier:@"next" sender:self];
  104.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement