Created
September 11, 2011 03:11
-
-
Save indragiek/1209118 to your computer and use it in GitHub Desktop.
Animated NSView redraws + scrolling
This file contains 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
@implementation NSView (SNRAdditions) | |
- (void)scrollPointAnimated:(NSPoint)point | |
{ | |
NSScrollView *scrollView = [self enclosingScrollView]; | |
NSClipView *clipView = [scrollView contentView]; | |
NSPoint constrainedPoint = [clipView constrainScrollPoint:point]; | |
[NSAnimationContext beginGrouping]; | |
[[NSAnimationContext currentContext] setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; | |
[[clipView animator] setBoundsOrigin:constrainedPoint]; | |
[NSAnimationContext endGrouping]; | |
[scrollView reflectScrolledClipView:clipView]; | |
} | |
- (NSImage*)NSImage | |
{ | |
NSSize viewSize = [self bounds].size; | |
NSBitmapImageRep *bir = [self bitmapImageRepForCachingDisplayInRect:[self bounds]]; | |
[bir setSize:viewSize]; | |
[self cacheDisplayInRect:[self bounds] toBitmapImageRep:bir]; | |
NSImage* image = [[NSImage alloc] initWithSize:viewSize]; | |
[image addRepresentation:bir]; | |
return image; | |
} | |
- (void)redrawAnimated | |
{ | |
NSImageView *imageView = [[NSImageView alloc] initWithFrame:self.bounds]; | |
imageView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; | |
imageView.image = self.NSImage; | |
[self addSubview:imageView]; | |
[self display]; | |
[NSAnimationContext beginGrouping]; | |
[[NSAnimationContext currentContext] setCompletionHandler:^(void) { | |
[imageView removeFromSuperview]; | |
}]; | |
[[imageView animator] setAlphaValue:0.f]; | |
[NSAnimationContext endGrouping]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment