Iphone MFMailComposeViewController和UITextField类别

Iphone MFMailComposeViewController和UITextField类别,iphone,objective-c,ios,Iphone,Objective C,Ios,我有UITextField类别。对于这个类别,MFMailComposeViewController将无法工作,当我演示MFMailComposeViewController时,它会崩溃,并且出现错误 Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 24.5]' 有人知道如何解决这个问题吗?试试: - (CGRect

我有UITextField类别。对于这个类别,MFMailComposeViewController将无法工作,当我演示MFMailComposeViewController时,它会崩溃,并且出现错误

Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 24.5]'

有人知道如何解决这个问题吗?

试试:

- (CGRect)textRectForBounds:(CGRect)bounds {
    if (CGRectIsNull(bounds) || CGRectIsInfinite(bounds)) {
        return bounds;
    }
    return CGRectInset( bounds , 30 , 5);
}
第二个函数也是这样


不过,您应该重命名这些函数,这样它们就不会与现有方法冲突,或者与子类冲突,而不是使用类别。

重写类别中的方法总是一个糟糕的主意。这不起作用,如果我重命名一个函数,自定义UITextField不起作用,正如我所说,您应该使用子类。:-)不过,这应该可以修复您的崩溃。
- (CGRect)textRectForBounds:(CGRect)bounds {
    if (CGRectIsNull(bounds) || CGRectIsInfinite(bounds)) {
        return bounds;
    }
    return CGRectInset( bounds , 30 , 5);
}