Created
July 8, 2013 11:48
-
-
Save mindbrix/5948093 to your computer and use it in GitHub Desktop.
How to draw rapidly refreshed string labels performantly using GCD.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)drawTimecodeUsingGCD | |
{ | |
if( dispatch_semaphore_wait( _timecodeSemaphore, DISPATCH_TIME_NOW ) != 0 ) | |
{ | |
return; | |
} | |
dispatch_async( _timecodeQueue, ^() | |
{ | |
float fontSize = ceilf( self.scrubberSize * 0.425f ); | |
UIFont *font = [ UIFont fontWithName:@"Courier" size:fontSize ]; | |
CGSize labelSize = [ _avPlayerView.timecode sizeWithFont:font ]; | |
UIGraphicsBeginImageContextWithOptions( labelSize, NO, [ UIScreen mainScreen ].scale ); | |
[[ UIColor blackColor ] set ]; | |
[ _avPlayerView.timecode drawAtPoint:CGPointZero withFont:font ]; | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
dispatch_async( dispatch_get_main_queue(), ^() | |
{ | |
self.timecodeImageView.image = image; | |
self.timecodeImageView.frame = CGRectMake( 0.0f, 0.0f, labelSize.width + self.thumbnailPadding, labelSize.height + self.thumbnailPadding ); | |
[ self.timecodeImageView centreHorizontally ]; | |
self.timecodeImageView.hidden = self.timecodeHidden; | |
dispatch_semaphore_signal( _timecodeSemaphore ); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment