0

我将 UITextField 的图层作为子图层添加到实际上是 UIImageView 的现有图层。我在图像视图上应用透视旋转,它工作正常。但是 UITextField 不会变为活动状态。发送给它的 beginFirstResponder 消息不显示键盘。点击它不起作用,它在用户交互中保持非活动状态。我还尝试为文本字段的图层设置 zPosition,使其位于 imageview 图层之上,并且是 zPosition。

    rightband = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right-band.png"]];
    rightband.layer.frame = CGRectMake(623.5, 310.5, 624, 210);
    rightband.layer.zPosition = 40.0f;


    usernameField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 260, 26)];
    usernameField.clearButtonMode = UITextFieldViewModeWhileEditing;
    usernameField.keyboardType = UIKeyboardTypeDefault;
    usernameField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    usernameField.borderStyle = UITextBorderStyleNone;
    usernameField.backgroundColor = [UIColor clearColor];
    usernameField.font = [UIFont fontWithName:@"HelveticaNeue" size:17];
    usernameField.textColor = UIColorFromRGB(0x303030);
    usernameField.textAlignment = UITextAlignmentLeft;
    usernameField.placeholder = @"Username";
    usernameField.autocorrectionType = UITextAutocorrectionTypeNo;
    usernameField.returnKeyType = UIReturnKeyNext;
    usernameField.delegate = self;
    usernameField.layer.anchorPoint = CGPointMake(1.0f, 0.5f);
    usernameField.layer.zPosition = 100.0f;
    usernameField.layer.frame = CGRectMake(10, 10, 260, 26); 
    [rightband.layer addSublayer:usernameField.layer];
4

2 回答 2

0

您可以尝试将视图层次结构更改为以下

UIView -> UIImageView 和 UITextField 不要将 UITextField 作为子项添加到 UIImageView UITextField 和 UIImageView 将是 UIView 的子项

于 2012-05-31T10:17:02.383 回答
0

您应该添加文本字段视图以使其响应触摸。这样做:

[rightband addSubview:usernameField];
于 2012-05-31T10:33:09.340 回答