然后按下按钮后卡片必须翻转,按钮应该改变它的颜色(实际上是图像).但它根本没有发生,所以在按钮改变之前翻转开始.这是我的代码:
//Adding a button to my vIEwUIbutton *changeStatebutton = [UIbutton buttonWithType:UIbuttonTypeCustom];[changeStatebutton setimage:[UIImage imagenamed:imagetoInitWith] forState:UIControlStatenormal];[changeStatebutton setimage:[UIImage imagenamed:imagetoInitWith] forState:UIControlStateHighlighted];changeStatebutton.frame = CGRectMake(0,30,30);changeStatebutton.center = CGPointMake(self.bounds.size.wIDth/2+([myWord length]*8)+17,35);changeStatebutton.tag = 77;[changeStatebutton addTarget:self action:@selector(changeStateIndicator:) forControlEvents:UIControlEventtouchUpInsIDe];[self addSubvIEw:changeStatebutton];//Method which is called when the button is touched- (voID)changeStateIndicator:(UIbutton *)sender{ [sender setimage:[UIImage imagenamed:@"StateYellow"] forState:UIControlStatenormal]; [sender setimage:[UIImage imagenamed:@"StateYellow"] forState:UIControlStateHighlighted]; currentWord.done = [NSNumber numberWithInt:currentWord.done.intValue-10]; [self prepareForTest];}//Method which flips the card- (voID)prepareForTest{ testSIDe = [[UIImageVIEw alloc]initWithImage:[UIImage imagenamed:@"cal_small3"]]; [UIVIEw TransitionFromVIEw:self toVIEw:testSIDe duration:0.5 options:UIVIEwAnimationoptionTransitionFlipFromright completion:nil];}
我的猜测是发送方不会改变它的图像,直到方法-changeStateIndicator结束它,但我不确定这是实际问题.请帮帮我.
解决方法 试着推迟这个电话:dispatch_async(dispatch_get_main_queue(),^{ [self prepareForTest]; });
如果那种工作但它仍然不是你想要的,那么使用dispatch_after()或
[self performSelector:@selector(prepareForTest) withObject:nil afterDelay:0.25f];
(如果你愿意,你可以使用时间为“0”的第二次调用而不是调度 – 同样的事情.)
总结以上是内存溢出为你收集整理的ios – 在调用setImage:之后,UIButton不会更新它的图像全部内容,希望文章能够帮你解决ios – 在调用setImage:之后,UIButton不会更新它的图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)