iphone sdk:CGAffineTransform 在 iOS 4 中不起作用?
我正在使用以下代码来移动其中包含 uitextfield 的 uialertview 。 当键盘出现时,alertView 应该向上滑动,当键盘消失时,alertView 应该向下滑动。以下代码在 ios 3.1.2 下对我来说工作得很好。但由于某种原因,它在 ios 4.0 下不起作用......问题似乎是我正在进行的转换,但我不知道到底出了什么问题。如果有人知道解决方案,那就太好了!提前致谢!这是我的代码:
- (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 = @"";
}
}
i'm using the following code to move a uialertview with a uitextfield in it.
The alertView is supposed to slide up when the keyboard appears and slide backdown as soon as it dissappears. The following code worked perfectly fine for me under ios 3.1.2. But for some reason it does not work under ios 4.0..... The issue seems to be the transformation i'm making but i have no idea what exactly is going wrong. It would be great if anyone knows a solution! Thanks in advance! here's my code:
- (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 = @"";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iOS 4 改变了 UIAlertView 中的行为,使得翻译变得不必要。尝试将翻译包装在 if 中以测试您是否使用的是 iOS 版本 << 4 并且只在那里应用它 - 这对我们的情况有所帮助。
例子:
iOS 4 changed the behavior in the UIAlertView making the translation unnecessary. Try wrapping the translation in an if to test if you are on an iOS version < 4 and only apply it there - that helped the situation we had.
Example: