iOS開発中の奇技淫巧

2601 ワード

目次

  • 削除Button的标题变更时的点灭动画

  • iOS 7とiOS 8でtableView分割線の先頭

  • 削除tableView下部的余分分割线

  • 防除键盘遮盖textFiled的软件


  • 削除Button的标题变更时的点灭动画


    buttonのtitleLabelを同時に設定する必要があります.textとsetTitleのみで、titleLabel.textは前に置く必要があります
     :
    [Button.titleLabel setText:string];
    [Button setTitle:string forState:UIControlStateNormal];

    iOS 7とiOS 8でtableView分割線の先頭


    次の2つの関数を上書きします.
    -(void)viewDidLayoutSubviews{
       if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
           [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
       }
    
       if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
       }
    }
    
    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
       if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
           [cell setSeparatorInset:UIEdgeInsetsZero];
       }
    
       if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
           [cell setLayoutMargins:UIEdgeInsetsZero];
       }
    }

    削除tableView下部的余分分割线

     [self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];

    防除键盘遮盖textFiled的软件


    キーボードのイジェクトとキーボードの両方のイベントを処理する必要があります
     
     textfield 
    - (void)textFieldDidBeginEditing:(UITextField *)textField{
       CGRect frame = textField.frame;
       CGPoint rootFrame = [[textField superview] convertPoint:frame.origin toView:self.view];// 
       int offset = rootFrame.y + 56 - (self.view.frame.size.height - 216.0);// 216
       NSTimeInterval animationDuration = 0.30f;
       [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
       [UIView setAnimationDuration:animationDuration];
       float width = self.view.frame.size.width;
       float height = self.view.frame.size.height;
       if(offset > 0){
           CGRect rect = CGRectMake(0.0f, -offset,width,height);
           self.view.frame = rect;
       }
       [UIView commitAnimations];
    }
    
     
    - (IBAction)hideKeyboard:(id)sender {
       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 
    }