Jac*_*nkr 1 uiview uiviewanimation ios
在ios动画中[UIView animatWithDuration...]如何在动画期间拦截动画值?
这是我目前的(不工作)解决方案:
#import "FooterSelectionView.h"
#import <QuartzCore/QuartzCore.h>
@implementation FooterSelectionView
@synthesize displayLink;
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// Initialization code
selector = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"selector.png"]];
[self addSubview:selector];
[self setSelectorFrame:CGRectMake(700, 0, selector.frame.size.width, selector.frame.size.height)];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
UIImage *bg = [UIImage imageNamed:@"overlayArea.png"];
[bg drawInRect:CGRectMake(0, 0, 957, 127) blendMode:kCGBlendModeNormal alpha:1];
[selector.image drawInRect:selector.frame blendMode:kCGBlendModeOverlay alpha:1];
}
-(void)step {
[self setNeedsDisplay];
NSLog(@"%@", @"step");
}
- (void)setSelectorFrame:(CGRect)frame {
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(step)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[UIView animateWithDuration:5 animations:^{
selector.frame = frame;
//self.alpha = 0
} completion:^(BOOL finished){
[self setNeedsDisplay];
[self.displayLink invalidate];
self.displayLink = nil;
NSLog(@"%@", @"stop");
}];
}
@end
Run Code Online (Sandbox Code Playgroud)
我看到实际的图像视图移动,但带有叠加的"绘制"版本仅立即转到目标值.我希望能够告诉"绘制"版本去实际的选择器视图.我怎样才能做到这一点?
当我NSLog将selector.frame.origin.x我注意到,该值始终0.我可以看到选择器是屏幕上的动画,所以给出了什么?
这里有一些错误:
不要尝试使用drawRect进行逐帧动画,它实际上不够快,因为Core Graphics不是硬件加速的(它可能在模拟器上看起来很好 - 它不会在真实设备上).
如果要为图像的矩形设置动画,请使用UIImageView并使用普通的UIView动画方法为其设置动画.
如果你看不到使用普通动画方法实现动画的方法,你可以使用displayLink逐帧进行,但你仍然应该只更新UIImageView的框架而不是直接在drawRect中绘制图像. .
UIView动画不view.frame直接为属性设置动画.如果您将view.frame其设置为立即设置为您指定的任何值,即使在设置动画时也是如此.尝试将逐帧动画同步到另一个视图的帧时,因为它为其设置了动画效果.
要获取动画视图帧的实际动画中间值,您需要查看view.layer.presentationLayer.frame- 这是动画的值.该view.frame实际上只是一个getter方法返回的view.layer.modelLayer.frame,它总是设置为任意值view.frame上一次的设置.
| 归档时间: |
|
| 查看次数: |
1307 次 |
| 最近记录: |