2012-05-31 33 views
0

我正在將UITextField的圖層作爲子圖層添加到實際上是UIImageView的現有圖層中。我在圖像視圖上應用透視旋轉並且工作正常。但是UITextField不會激活。它的beginFirstResponder消息不顯示鍵盤。點擊它不起作用,它在用戶交互中保持不活動狀態。我也嘗試爲文本框的圖層設置zPosition,以便它位於imageview圖層上方,並且它是zPosition。UITextField作爲子圖層

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]; 

回答

0

您應該添加文本字段視圖,以便它響應觸摸。 所以呢:

[rightband addSubview:usernameField]; 
+0

沒錯。我想了很多。但是,然後我創建右帶(透視旋轉)的動畫。直到它是子圖層時,應用子圖層轉換纔會起作用。 – Bourne

+0

你可以發佈你的動畫代碼嗎? – giorashc

0

你可以嘗試將視圖層次結構更改爲以下

的UIView - >的UIImageView,同時也是UITextField 不要添加的UITextField作爲一個孩子的UIImageView 的UITextField和UIImageView的將是兩個孩子的一個UIView

相關問題