1

我有一个视图(实际上是一个 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
}

请注意,不知何故,视图的大小发生了变化。我无法理解这可能发生在哪里/为什么/如何发生。还有什么想法可以看吗?

4

1 回答 1

0

要查找视图何时调整大小,您可以子类化 uiview 并覆盖以下内容

- (void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
}

现在每次视图改变它的大小时都会调用这个函数

于 2012-05-31T10:01:38.037 回答