IOS - iPhone: UISlider track image disappears randomly

I have a customized UISlider that sometimes has a track image. This happens randomly, and when its parent view controller is mapped to visible (I never see it actually disappear).

Here is my code for configuring UISlider:

timeSlider = [[UISlider alloc] initWithFrame:CGRectMake(55, 8, 210, 23)]; timeSlider.backgroundColor = [UIColor clearColor]; UIImage *blutrackImg = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bluetrack" ofType:@"png"]]; UIImage *whitetrackImg = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"whitetrack" ofType:@"png"]]; //UIEdgeInsetsMake(top,left,bottom,right) UIImage *stetchLeftTrack = [blutrackImg stretchableImageWithLeftCapWidth:9.0 topCapHeight:0.0]; UIImage *stetchRightTrack = [whitetrackImg stretchableImageWithLeftCapWidth:9.0 topCapHeight:0.0]; [timeSlider setThumbImage: [UIImage imageNamed:@"whiteslide2.png"] forState:UIControlStateNormal]; [timeSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal]; [timeSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal]; timeSlider.continuous = NO; [timeSlider addTarget:self action:@selector(trackTime:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:timeSlider]; 

I built iOS 5.0. Has anyone ever encountered such a problem?

+4
source share
4 answers

SOLUTION FOUND: I believe that this problem was caused by the following error:

I had a timer that set the value of the slider using the slider.value property, and not the [slider setValue: animated:] method. I was also not sane, checking the set value.

Solving these problems solved the problem.

+8
source

Secondly, the "Answer" and I want to use esp. point a little about sanity by checking the values. I do not think this is important if you use slider.value or [slider setValue], setting it to NaN, then the background disappears in iOS5.

NB: Getting NaN as the return value can happen often if you use the iPod library and request the current position.

+5
source

I had the same problem, it was caused by duplication resources. Check it out during the build steps if it renames the sources to xCode.

+2
source

NaN was my problem too, but it was worse than I expected ... even if UISlider installed NAN once, on iOS5 it seems that it broke this control instance forever, it was amazing and it took a little time to track.

+1
source

Source: https://habr.com/ru/post/1396908/


All Articles