在我的应用程序中,我有一个用于OTP输入的自定义编辑文本,我想为此视图创建一个转换方法,以便用户可以看到实际输入一秒钟,它将替换为子弹。就像使用密码输入的原生edittext一样。
private class PinTransformationMethod extends PasswordTransformationMethod {
private char BULLET = '\u2B24';
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return new PasswordCharSequence(source);
}
private class PasswordCharSequence implements CharSequence {
private final CharSequence source;
public PasswordCharSequence(@NonNull CharSequence source) {
this.source = source;
}
@Override
public int length() {
return source.length();
}
@Override
public char charAt(int index) {
return BULLET;
}
@Override
public CharSequence subSequence(int start, int end) {
return new PasswordCharSequence(this.source.subSequence(start, end));
}
}
}
这是我从PasswordTransformation方法扩展的转换方法。它可以完美地替换我对Bullets的输入,但是我无法显示输入几秒钟,我该如何实现呢?
答案 0 :(得分:0)
如果有人需要做这样的事情,我在我的char - (void)disableWaitForIdle {
SEL originalSelector = NSSelectorFromString(@"waitForQuiescenceIncludingAnimationsIdle:");
SEL swizzledSelector = @selector(doNothing);
Method originalMethod = class_getInstanceMethod(objc_getClass("XCUIApplicationProcess"), originalSelector);
Method swizzledMethod = class_getInstanceMethod([self class], swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
}
- (void)doNothing {
// no-op
}
中使用了Thread.sleep
,因为 500 毫秒延迟method