gpt4 book ai didi

iphone - 如何找到调整 View 大小的位置/原因?

转载 作者:行者123 更新时间:2023-11-28 17:32:30 25 4
gpt4 key购买 nike

我有一个 View (实际上是一个 UIControl)作为我的 UIViewController 的一部分。这个 View 是在 IB 中设计的,然后在代码中,根据一些用户的操作,我正在更改 View 的框架。整个事情都发生在 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 中我看到了正确的宽度和高度值。然而,当显示 View 时,它的尺寸发生了变化。然后我将相同的调试添加到 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
}

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

最佳答案

要查找何时调整 View 大小时,您可以将 uiview 子类化并覆盖以下

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

现在每次 View 改变大小时都会调用这个函数

关于iphone - 如何找到调整 View 大小的位置/原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10831339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com