2010-08-23 70 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 
}