2010-08-23 61 views
0

我使用下面的代碼來移動uitextview和uitextfield。 當鍵盤出現時,alertView應該向上滑動,並在消失後立即滑落。下面的代碼在ios 3.1.2下工作得非常好。但由於某種原因,它不能在ios 4.0下工作.....這個問題似乎是我正在進行的轉換,但我不知道到底發生了什麼問題。如果有人知道解決方案,這將是非常棒的!提前致謝!這裏是我的代碼:iphone sdk:CGAffineTransform無法在iOS 4中使用?

- (void)addItemAction{ 

workoutName = [[UIAlertView alloc] initWithTitle:@"New Workout" message:@"Insert the name of your new workout:\n    " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Done", nil]; 
workoutName.cancelButtonIndex = 0; 
UITextField *titleField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 90.0, 260.0, 25.0)]; 
titleField.delegate = self; 
titleField.borderStyle = UITextBorderStyleRoundedRect; 
titleField.returnKeyType = UIReturnKeyDone; 
[workoutName addSubview:titleField]; 
[workoutName show]; 

} 
- (BOOL)textFieldShouldReturn:(UITextField *)textField { 

[textField resignFirstResponder]; 
return YES; 

} 



- (void)textFieldDidBeginEditing:(UITextField *)textField { 

[UIView beginAnimations:nil context:NULL]; 
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, -70.0); 
[workoutName setTransform:myTransform]; 
[UIView commitAnimations]; 

} 


- (void)textFieldDidEndEditing:(UITextField *)textField { 

[UIView beginAnimations:nil context:NULL]; 
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 0.0); 
[workoutName setTransform:myTransform]; 
[UIView commitAnimations]; 
if ([textField.text length] != 0) { 
    self.newWorkout = textField.text; 
} 
else { 
    self.newWorkout = @""; 
} 

} 

回答

1

iOS 4改變了UIAlertView中的行爲,使翻譯成爲不必要的。如果您在iOS版本< 4中嘗試將翻譯包裝在if中以測試,並且僅在那裏應用它 - 這有助於我們的情況。

實施例:

if ([[[UIDevice currentDevice] systemVersion] floatValue] < 4.0) { 
    // translation goes here 
}