简体   繁体   English

隐藏的XCode 4 UILabel似乎不起作用

[英]XCode 4 UILabel hidden doesn't seem to work

I'm having some display trouble wherein I manipulate a UILabel, and even though I use 我在操作UILabel时遇到了一些显示问题,即使我使用了

myLabel.hidden=YES; ...manipulation code... myLabel.hidden=NO;

the label never 'hides' and the manipulation (CATransform3DMakeRotation) is shown (you can see the label flip). 标签从不“隐藏”,并且显示了操作(CATransform3DMakeRotation)(您可以看到标签翻转)。

In XCode, I set a breakpoint at the "myLabel.hidden=YES;" 在XCode中,我在“ myLabel.hidden = YES;”处设置了一个断点。 line, but as I step through the code, it doesn't hide. 行,但是当我逐步执行代码时,它不会隐藏。

I must be missing something to get the "hidden" method to implement, right? 我必须缺少一些东西才能实现“隐藏”方法,对吗? Some kind of refresh or update to the label? 某种刷新或更新标签? Thanks... 谢谢...

Here's the code. 这是代码。 "SetStartPosition" is called from several places, not just "doubleTap". 从多个地方调用“ SetStartPosition”,而不仅仅是“ doubleTap”。

-(void)doubleTap{
    //stop the timer
    [myMover invalidate]; //the timer simply moves the label position
    myMover = nil;
    msgLabel.hidden=YES;
    isMirrored=!isMirrored;
    [self setStartPosition]; //flips the label
    msgLabel.hidden=NO;
    //restart the timer
    [self runMover];
}

- (void)setStartPosition{
    if(isMirrored){
        startPosition=(msgLabel.frame.size.width/2) * -1;
        msgLabel.layer.transform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f); //M_PI rotates 180 degrees
    }else{
        startPosition=(screenHeight)+(msgLabel.frame.size.width/2);
        msgLabel.layer.transform = CATransform3DMakeRotation(0.0, 0.0f, 1.0f, 0.0f); //0.0 rotate to normal
    }
    newX=startPosition;
    newY=screenWidth/2;
    newFrame = msgLabel.frame;
    newFrame.size.height = screenWidth;
    newFrame.origin.x =newX;
    newFrame.origin.y=newY;
    msgLabel.frame = newFrame;
}

No drawing is done during method execution, it is all done at the next drawing cycle. 在方法执行期间不执行任何绘制,所有操作均在下一个绘制周期完成。 If your code above is all executed in the same method then the final state of the label will be visible, since you hide and then re-show it before any drawing is done. 如果上面的代码全部以相同的方法执行,则标签的最终状态将可见,因为在完成任何绘制之前,先将其隐藏然后重新显示。

If you expand your question to include more context it will be easier to offer a solution. 如果您将问题扩展为包括更多上下文,则提供解决方案将更加容易。

It looks as if you are getting an animation you don't want because you are modifying an animatable property of a CALayer, giving you an implicit animation. 看起来好像正在获取不需要的动画,因为您正在修改CALayer的可动画设置的属性,从而为您提供了隐式动画。 Please see here for guidance on how to override the timing of implicit animations - see "temporarily disabling layer actions" 请参见此处以获取有关如何替代隐式动画的时间的指导-请参见“临时禁用图层操作”

An alternative is that you are being animated unintentionally because the timer method had queued up a pending change, and your transform is being done at the same time, so it is done in the animation. 另一种选择是您无意中制作了动画,因为timer方法已将待处理的更改排队,并且您的转换是同时完成的,因此它是在动画中完成的。 You should remove any animations from the label before changing the transform. 更改变换之前,应从标签中删除所有动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM