iphone sdk:CGAffineTransform 在 iOS 4 中不起作用?

发布于 2024-09-15 18:55:06 字数 1515 浏览 3 评论 0原文

我正在使用以下代码来移动其中包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一刻暧昧 2024-09-22 18:55:06

iOS 4 改变了 UIAlertView 中的行为,使得翻译变得不必要。尝试将翻译包装在 if 中以测试您是否使用的是 iOS 版本 << 4 并且只在那里应用它 - 这对我们的情况有所帮助。

例子:

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

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:

if ([[[UIDevice currentDevice] systemVersion] floatValue] < 4.0) {
    // translation goes here
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文