我有一个视图(实际上是一个UIControl)作为我的UIViewController的一部分。这个视图是在IB中设计的,然后在代码中根据一些用户的动作设计,我正在改变视图的框架。整个过程都发生在CATransition中。代码如下所示:
CATransition *anim = [CATransition animation];
anim.type = kCATransitionFade;
anim.duration = 0.5;
anim.delegate = self;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[mainPanel.layer addAnimation:anim forKey:@"changeTextTransition"];
float totalHeight = ...; // this is the Y of the frame
float max_width = ...; // this is the width of the frame
float bh = ...; // this is the height of the frame
... //some computations to determine the frame for my view
[blockView setFrame:CGRectMake(0, totalHeight, max_width, bh)];
//This is for debugging
CGSize sg = answer1.frame.size;
NSLog(@"width: %f, height: %f", sg.width, sg.height);
//This outputs: width: 260.000000, height: 29.000000
到目前为止一切都很好,在NSLog中我看到正确的宽度和高度值。然而,当显示视图时,其尺寸已经改变。然后我将相同的调试添加到animationDidStop
- 并看到不同的结果:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
[scroll flashScrollIndicators];
CGSize sg = answer1.frame.size;
NSLog(@"width: %f, height: %f", sg.width, sg.height);
//This outputs: width: 280.000000, height: 49.000000
}
请注意某处某处视图的大小已更改。我不知道在哪里/为什么/如何发生这种情况。还有什么想法可以看吗?
答案 0 :(得分:0)
要查找调整视图的大小,您可以继承uiview并覆盖以下
- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];
}
现在每次视图改变其大小时都会调用此函数