Objective c iOS8动画代码不再工作
在XCode版本6.0(6A215l)之前,我用来制作UITextField动画的代码一直适用于我。现在XCode6 Beta7不能重新定位UITextField。我该怎么做才能让它工作? 代码如下:Objective c iOS8动画代码不再工作,objective-c,uitextfield,ios8,Objective C,Uitextfield,Ios8,在XCode版本6.0(6A215l)之前,我用来制作UITextField动画的代码一直适用于我。现在XCode6 Beta7不能重新定位UITextField。我该怎么做才能让它工作? 代码如下: @interface TableConfigViewController () @property(nonatomic, strong) IBOutlet UITextField *customTableName; @end - (void)viewDidLo
@interface TableConfigViewController ()
@property(nonatomic, strong) IBOutlet UITextField *customTableName;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
[self.customTableName setDelegate:self];
}
- (void)animateTextField:(UITextField*)textField
up:(BOOL)up
{
const float movementDuration = 0.5f;
const int movementDistance = 380;
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: @"animation" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:movementDuration];
self.customTableName.frame = CGRectOffset(self.customTableName.frame, 0, movement);
[UIView commitAnimations];
}
- (void)textFieldDidBeginEditing:(UITextField*)textField
{
[self animateTextField:textField up:YES];
}
- (void)textFieldDidEndEditing:(UITextField*)textField
{
[self animateTextField:textField up:NO];
}
提前感谢
< P >不确定这是否是你问题的根源,但是你应该考虑使用基于块的API(从iOS 4可用)用于UIVIEW动画。 来自苹果关于beginAnimations:context:
“在iOS 4.0及更高版本中不鼓励使用此方法。您应该使用基于块的动画方法来指定动画。”
例如(未经测试):
非常感谢您的回复@WorkingDev,我按照苹果的文档建议使用了这些块,但仍然不起作用。我尝试了“块”解决方案,仍然无法在iOS 8上运行(在iOS 7.x上运行良好)。
- (void)animateTextField:(UITextField*)textField
up:(BOOL)up
{
const float movementDuration = 0.5f;
const int movementDistance = 380;
int movement = (up ? -movementDistance : movementDistance);
[UIView animateWithDuration:movementDuration
animations:
^{
self.customTableName.frame = CGRectOffset(self.customTableName.frame, 0, movement);
}
];
}