Requirements: After clicking the play button music, button background frequent switching between 1.png and 2.png
The current code:
- (Void) btnImageChange {
bool c = FALSE;
while (! playFinish) {/ / not finished music, button's image has been changed
Play
while (c) {
/ / I put the picture into an array of advance deposit objact in an array called soundImage
[SoundBtn setImage: [soundImage objectAtIndex: 0] forState: UIControlStateNormal];
NSLog (@ "aaaa");
c = FALSE;
[NSThread sleepForTimeInterval: 0.5]; / / change this thread to sleep after 500 milliseconds
}
[SoundBtn setImage: [soundImage objectAtIndex: 1] forState: UIControlStateNormal];
NSLog (@ "bbbb");
c = TRUE;
[NSThread sleepForTimeInterval: 0.5]; / / change this thread to sleep after 500 milliseconds
}
}
Console Print:
bbbb
aaaa
bbbb
aaaa
bbbb
aaaa
bbbb
aaaa
headache of the day the question is: are they not changed the picture and print properly explain two of setImage are performed Why would the same console without the slightest exception, ah, God, come help me ~ ~ ~ ~
Weak weak to ask: iphone middle button is not set to be clear about the finished image, or behind the image and then set it to no avail, but the specific clear what is not clear, but Hucai also invited Daniel to answer
Reply:
To determine [soundImage objectAtIndex: 0] is taken out of UIImage, if other type, then the picture will not change.
Suggested [soundImage objectAtIndex: 0] separate out debugging, and setimage not function together.
Reply:
To determine [soundImage objectAtIndex: 0] is taken out of UIImage, if other type, then the picture will not change.
Suggested [soundImage objectAtIndex: 0] separate out debugging, and setimage not function together.
Reply:
Changes in general need to set the picture settings will be updated in the main thread, I have encountered similar problems in modifying tableView pictures when using performSelectorOnMainThread executed in the main thread should change the button's image can solve this problem
Reply:
Perhaps it can be:
Before play began to display animation, with perform afterDealy
Then play audio
End stop animation
Reply:
[SoundBtn setImage: [UIImage imageNamed: [m_imagviewarray objectAtIndex: 0]] forState: UIControlStateNormal];
This can be changed
Reply:
[SoundBtn setImage: [UIImage imageNamed: [soundImage objectAtIndex: 0]] forState: UIControlStateNormal];
This can be changed
Reply:
There is a case to try
The method may not be redrawn trigger
ViewSetNeedsDisplay manually redraw it, look at the picture can show
Reply:
The picture advance deposit into a objact array, the array is called soundImage
----------
Determined not been released, can be read out correctly.
Reply:
Reply:
Reply:
Code obvious question:
Code is running in a bar in the UI, UI thread runs out will refresh;
NSThread blocking 500ms, UI thread will be blocked 500ms, so the picture changes effect you do not see.
You need to put [soundBtn setImage: [soundImage objectAtIndex: 1] forState: UIControlStateNormal];
This code into
performOnMainThread ..... WaitUntilDone: NO way to go to achieve the job to enforce refresh.
No comments:
Post a Comment