美文网首页
iOS应用开发实战(5-6)-App"猜城市"

iOS应用开发实战(5-6)-App"猜城市"

作者: 逸飞u | 来源:发表于2016-03-06 19:24 被阅读60次

    这是首次在课上遇到完整的app,对这个app的设计步骤准备作为以后自己做project时候的参考。

    课题

    猜城市.png
    • step1:需求分析
    需求分析.png
    • step2:分析设计


      分析设计.png
    • step3:程序设计

    程序设计.png
    • step4:代码结构
    代码结构.png

    键盘的显示问题

    我写了一个类,不知道思路对不对

    • .h文件
      // keyboardEvents.h
      #import <UIKit/UIKit.h>
      @interface keyboardEvents : UIViewController<UITextFieldDelegate>
      -(void)moveView:(float)move;
      @end

    • .m文件
      // keyboardEvents.m
      #import "keyboardEvents.h"
      @interface keyboardEvents ()
      @end
      int textFieldY;
      @implementation keyboardEvents
      #pragma mark - Keyboard Events
      -(void)textFieldDidBeginEditing:(UITextField *)textField{
      textFieldY = textField.frame.origin.y;
      }

      -(void)textFieldDidEndEditing:(UITextField *)textField{
          int offset = 0;
          [self moveView:offset];
          [UIView commitAnimations];
      }
      
      -(BOOL)textFieldShouldReturn:(UITextField *)textField
      {
         NSTimeInterval animationDuration = 0.30f;
        [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
        [UIView setAnimationDuration:animationDuration];
        CGRect rect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height);
        self.view.frame = rect;
        [UIView commitAnimations];
        [textField resignFirstResponder];
        return YES;
      }
      
      - (void) registerForKeyboardNotifications
      {
          [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(KeyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil];
      }
      
      - (void) KeyboardWillShowNotification:(NSNotification *) notif
      {
          NSDictionary *info = [notif userInfo];
          NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
          CGFloat keyboardY = [value CGRectValue].origin.y;
      
          if (textFieldY > keyboardY -60 ){
              int offset =  ( keyboardY - 60 ) - textFieldY ;
              [self moveView:offset];
              [UIView commitAnimations];
          }
      }
      
      -(void)moveView:(float)move{
          NSTimeInterval animationDuration = 0.30f;
          CGRect frame = self.view.frame;
          frame.origin.y = 0;
          frame.origin.y +=move;
          self.view.frame = frame;
          [UIView beginAnimations:@"ResizeView" context:nil];
          [UIView setAnimationDuration:animationDuration];
          self.view.frame = frame;
          [UIView commitAnimations];
      }
      
      #pragma mark - View Lifecycle
      - (void)viewDidLoad {
          [super viewDidLoad];
          [self registerForKeyboardNotifications];
      }
      
      - (void)didReceiveMemoryWarning {
          [super didReceiveMemoryWarning];
          [[NSNotificationCenter defaultCenter]removeObserver:self];
      }
      @end

    相关文章

      网友评论

          本文标题:iOS应用开发实战(5-6)-App"猜城市"

          本文链接:https://www.haomeiwen.com/subject/eueakttx.html