Reputation: 2394
Here is my code. it's simple. My question is why the animation still on when the main thread doing other things,the docs says the main thread can update the ui. the main thread can do two things in the same time???
may be the GPU make the animation?
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 80, 50)];
testLabel.font = [UIFont systemFontOfSize:15.0f];
testLabel.backgroundColor = [UIColor redColor];
testLabel.text = @"Hello world";
testLabel.adjustsFontSizeToFitWidth = YES;
[self.view addSubview:testLabel];
[UIView animateWithDuration:10
animations:^{
testLabel.frame = CGRectMake(100, 200, 80, 50);
} completion:^(BOOL finished) {
//
}];
[self performSelector:@selector(hello:) withObject:@"hello" afterDelay:2];
}
- (void)hello:(NSString *)hello{
for (int i = 0; i < 100000; i++) {
NSInteger j = i *5;
NSLog(@"%d",j);
}
NSLog(@"%@",hello);
}
Upvotes: 0
Views: 354
Reputation: 6952
The animation is run in graphics hardware, it even doesn't bother CPU.
Core animation is under UIKit
, so when you use animateWithDuration:animations:completion:
of UIView
, you are using Core animation actually.
I reference a paragraph in the CoreAnimation_guide :
Core Animation is a graphics rendering and animation infrastructure available on both iOS and OS X that you use to animate the views and other visual elements of your app. With Core Animation, most of the work required to draw each frame of an animation is done for you. All you have to do is configure a few animation parameters (such as the start and end points) and tell Core Animation to start. Core Animation does the rest, handing most of the actual drawing work off to the onboard graphics hardware to accelerate the rendering. This automatic graphics acceleration results in high frame rates and smooth animations without burdening the CPU and slowing down your app.
I think it is clear enough to answer your question.
Upvotes: 3