2015-01-09 99 views
-2

動畫不適用於iOS8,但在iOS7中運行良好。我可以知道如何解決這個問題嗎?動畫無法在iOS8中工作

[UIView animateWithDuration:0.5 animations:^{ 
}completion:^(BOOL finished) { 


    }]; 

回答

0

什麼是我用於iOS7的代碼與我用於iOS8的相同代碼及其工作正常。 在iOS8中做動畫沒有任何改變。你可以使用下面的代碼來做動畫。

[UIView animateWithDuration:0.75 animations:^{ 
self.dropdownTable.frame=CGRectMake(419, 184, 606, 331); 
}]; 
+0

它在從setframe更改爲.frame後工作。謝謝 – user4302196

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的和其它性質)的塊。