Iphone 如何找到视图调整大小的位置/原因?

Iphone 如何找到视图调整大小的位置/原因?,iphone,ios,animation,uiview,size,Iphone,Ios,Animation,Uiview,Size,实际上我有一个视图,一个UIControl作为我的UIViewController的一部分。这个视图是在IB中设计的,然后在代码中,根据一些用户的操作,我正在更改视图的框架。整个事情都发生在CatTransition内部。代码如下所示: CATransition *anim = [CATransition animation]; anim.type = kCATransitionFade; anim.duration = 0.5; anim.delegate = self; anim.timin

实际上我有一个视图,一个UIControl作为我的UIViewController的一部分。这个视图是在IB中设计的,然后在代码中,根据一些用户的操作,我正在更改视图的框架。整个事情都发生在CatTransition内部。代码如下所示:

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
}

请注意,视图的大小在某个地方发生了变化。我不知道这可能发生在哪里/为什么/如何。还有什么地方可以查看吗?

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

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

现在,每次视图更改其大小时都会调用此函数

这是执行此操作的一种方法,但似乎工作量太大了。子类化UIControl、更改我的代码和更改NIB,所有这些都只是为了查找谁/何时调用其中一个方法。如果我不能用其他方法解决的话,我可能不得不这么做。希望你能用一种更简单的方法找到它,但这是我知道的最快的方法。是的,看起来我必须走这条路。我会接受这个答案,因为它绝对有效。