动画在iOS8中不起作用,但在iOS7中运行良好。我可以知道如何解决这个问题吗?
[UIView animateWithDuration:0.5 animations:^{
}completion:^(BOOL finished) {
}];
答案 0 :(得分:1)
带有块的动画在iOS7和iOS8中均可正常运行。 有关更多信息,您应该将您的xcode项目转到UIKit.framework。然后你应该找到UIView.h类。在那里你找到:
@interface UIView(UIViewAnimationWithBlocks)
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL
/* Performs `animations` using a timing curve described by the motion of a spring. When `dampingRatio` is 1, the animation will smoothly decelerate to its final model values without oscillating. Damping ratios less than 1 will oscillate more and more before coming to a complete stop. You can use the initial spring velocity to specify how fast the object at the end of the simulated spring was moving before it was attached. It's a unit coordinate system, where 1 is defined as travelling the total animation distance in a second. So if you're changing an object's position by 200pt in this animation, and you want the animation to behave as if the object was moving at 100pt/s before the animation started, you'd pass 0.5. You'll typically want to pass 0 for the velocity. */
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // toView added to fromView.superview, fromView removed from its superview
/* Performs the requested system-provided animation on one or more views. Specify addtional animations in the parallelAnimations block. These additional animations will run alongside the system animation with the same timing and duration that the system animation defines/inherits. Additional animations should not modify properties of the view on which the system animation is being performed. Not all system animations honor all available options.
*/
+ (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray *)views options:(UIViewAnimationOptions)options animations:(void (^)(void))parallelAnimations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);
@end
它应该对你有所帮助。也不要忘记更改UIViewGeometry以制作动画。 例如:
UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(20.f, 20.f, 50.f, 50.f)];
testView.backgroundColor = [UIColor greenColor];
[self.view addSubview:testView];
[UIView animateWithDuration:2.f animations:^{
testView.center = self.view.center;
} completion:^(BOOL finished) {
NSLog(@"Complete = %d", finished);
}];
您还可以在动画块(以及UIView的其他属性)中更改颜色,alpha。
答案 1 :(得分:0)
我在iOS7上使用的代码与iOS8使用的代码相同,并且工作正常。 在iOS8中进行动画没有变化。您可以使用下面的代码来制作动画。
[UIView animateWithDuration:0.75 animations:^{
self.dropdownTable.frame=CGRectMake(419, 184, 606, 331);
}];