如何设计 UI 以支持 iPhone 和 iPad 的所有屏幕

How To Design an UI to support all the screens of iPhones and iPads

我正在做一个项目,我必须支持所有 iPhones 屏幕,例如 (iPhone4, iPhone 4S, iPhone 5S, iPhone 6, iPhone 6+) and iPads(iPad Mini, iPad Air, iPad Air 2, iPad 4, ETC)。

我正在考虑将 AutoLayout 和 AdaptiveLayout 用于 UI 设计。我了解到这一点并尝试将其应用到我的项目中。我在自动布局和自适应布局方面的设计或多或少是成功的,但是,当用户编辑文本字段时,调整文本字段的大小存在问题。

当用户尝试编辑文本字段时,我们需要将文本字段置于键盘顶部。所以,这可以在代码中完成,但是,当我们使用自动布局时,这段代码现在不起作用。 根据概念,当我们使用自动布局时,我们无法通过代码动态调整视图中控件的框架。

我现在被击中了吗?。请帮我解决这些问题。提前致谢

#pragma mark ----- Text field -----
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    // scroll up current text field
    [self animateTextField:textField up:YES withOffset:textField.frame.origin.y / 2];   
}

-(void)textFieldDidEndEditing:(UITextField *)textField{

  [self animateTextField:textField up:NO withOffset:textField.frame.origin.y / 2];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    [textField resignFirstResponder];
    return true;
}
#pragma mark ---- Text field scroll Up -----
-(void)animateTextField:(UITextField*)textField up:(BOOL)up withOffset:(CGFloat)offset
{
    const int movementDistance = -offset;
    const float movementDuration = 0.4f;
    int movement = (up ? movementDistance : -movementDistance);
    [UIView beginAnimations: @"animateTextField" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    [UIView commitAnimations];
}

试试这个,它会帮助你

请参阅此 link 以获得答案。即使我们使用 AutoLayout,它也会帮助我们将文本框置于顶部。

https://github.com/michaeltyson/TPKeyboardAvoiding/blob/master/TPKeyboardAvoiding/TPKeyboardAvoidingScrollView.m