iphone - 在没有 ScrollView 的简单 UIVIew 中,当 UITextField 出现键盘时调整界面?

标签 iphone xcode interface-builder

有没有办法将简单 UIView 中的某些文本字段向上移动,以便它们无法隐藏在键盘后面。?不使用UIScrollView是否可以

最佳答案

应该可以调整 UITextField 所在 View 的框架位置。查看此代码:

http://iphoneincubator.com/blog/tag/uitextfield

- (void)textFieldDidBeginEditing:(UITextField *)textField {  
    [self scrollViewToCenterOfScreen:textField];  
}  

- (void)scrollViewToCenterOfScreen:(UIView *)theView {  
    CGFloat viewCenterY = theView.center.y;  
    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];  

    CGFloat availableHeight = applicationFrame.size.height - keyboardBounds.size.height;            // Remove area covered by keyboard  

    CGFloat y = viewCenterY - availableHeight / 2.0;  
    if (y < 0) {  
        y = 0;  
    }  
    scrollView.contentSize = CGSizeMake(applicationFrame.size.width, applicationFrame.size.height + keyboardBounds.size.height);  
    [scrollView setContentOffset:CGPointMake(0, y) animated:YES];  
}  

关于iphone - 在没有 ScrollView 的简单 UIVIew 中,当 UITextField 出现键盘时调整界面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/909562/

相关文章:

iphone - 为什么选项卡式应用程序模板没有 "Use Core Data"复选框

iphone - 从另一个具有 objective-c 的函数更改我的函数的参数值

ios - 是否可以通过 Interface Builder 删除表格 View 底部的空单元格

ios - Xcode - 如何修复 'NSUnknownKeyException' ,原因 : … this class is not key value coding-compliant for the key X"error?

ios - xcode MKMapView 确实失败,错误为 : Error Domain=kCLErrorDomain Code=1 "(null)"

ios - @IBDesignable 错误 : IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool crashed

ios - iPhone 应用内购买商店工具包错误-1003 "Cannot connect to iTunes Store"

iphone - linkedin 连接 API 给出错误 401 - iphone

objective-c - NSManagedObjectContext的performBlock方法是否保证操作顺序?

swift - 在 Xcode 中以 Release模式运行 Swift 包测试