Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Everytime <code>changedValue:</code> gets called you create a new UIView, UIImageView and UILabel.<br> Instead of editing the old instances. That results that all old UIViews build a "path".</p> <p>In your viewDidLoad you can create these three views and set on each the <code>.tag property</code><br> <strong>viewDidLoad</strong> </p> <pre><code>UIView* bubble = [[UIView alloc]init]; UIImageView* back = [[UIImageView alloc]initWithImage:[UIImageimageNamed:@"sliderBar_handle_number.png"]]; UILabel * val = [[UILabel alloc]init] //other configurations ... bubble.tag = 1; back.tag = 2; val.tag = 3; [self.view addSubview:bubble]; [bubble addSubview:back]; [bubble addSubview:val]; </code></pre> <p>Now remove all the allocations, because we want to reuse the existing views. And we know their tags.<br> <strong>(void)valueChanged:(id)sender</strong></p> <pre><code>UISlider *localSlider = (UISlider *)sender; NSString* greenSliderValue = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%3.0f", [localSlider value]]]; UIView *bubble = (UIView*)[self.view.subviews viewWithTag:1]; UIImageView *back = (UIImageView*)[bubble.subviews viewWithTag:2]; UILabel *val = (UILabelw*)[bubble.subviews viewWithTag:3]; dsp =[greenSliderValue floatValue]; val.text = greenSliderValue; [bubbleViewController updateSliderValueTo:dsp]; CGFloat sliderMax = localSlider.maximumValue; CGFloat sliderMin = localSlider.minimumValue; CGFloat sliderMaxMinDiff = sliderMax - sliderMin; CGFloat sliderValue = dsp; if(sliderMin &lt; 0.0) { sliderValue = dsp-sliderMin; sliderMax = sliderMax - sliderMin; sliderMin = 0.0; sliderMaxMinDiff = sliderMax - sliderMin; } CGFloat xCoord = ((sliderValue-sliderMin)/sliderMaxMinDiff)*[localSlider frame].size.width-bubbleViewController.view.frame.size.width/2.0; CGFloat halfMax = (sliderMax+sliderMin)/2.0; if(sliderValue &gt; halfMax) { sliderValue = (sliderValue - halfMax)+(sliderMin*1.0); sliderValue = sliderValue/halfMax; sliderValue = sliderValue*11.0; xCoord = xCoord - sliderValue; } else if(sliderValue &lt; halfMax) { sliderValue = (halfMax - sliderValue)+(sliderMin*1.0); sliderValue = sliderValue/halfMax; sliderValue = sliderValue*11.0; xCoord = xCoord + sliderValue; } bubble.frame = CGRectMake(xCoord, 500, bubbleViewController.view.frame.size.width, bubbleViewController.view.frame.size.height); </code></pre> <p>now you can use your existing instances</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload