質問

I am having a really weird issue trying to use a UISlider, when I change the maximumValue of the slider to > 1.0, I get this weird duplicate slider appearing on my view. Please help :)

Heres what it looks like when slider.maximumValue = 10.0; http://imagizer.imageshack.us/v2/800x600q90/827/kf12.png

Heres what it looks like when slider.maximumValue = 1.0; http://imagizer.imageshack.us/v2/800x600q90/197/bcvf.png

Is there some behaviour of a UISlider I am missing? Here is my code for configuring the slider...

-(void)layoutSubviews
{
    [super layoutSubviews];

    CGSize viewSize = self.contentSubview.bounds.size;

    self.timeSlider.frame = CGRectMake(viewSize.width / 2 - 80,
                                       viewSize.height / 2 - 12,
                                       viewSize.width / 2,
                                       24);

    -(void)configureSubviews
    {
        [super configureSubviews];

        self.timeSlider = [[UISlider alloc] initWithFrame:CGRectZero];
        self.timeSlider.continuous = YES;
        self.timeSlider.minimumValue = 0;
        self.timeSlider.maximumValue = 1.0f;
        [self.timeSlider addTarget:self action:@selector(timeValueChanged:) forControlEvents:UIControlEventValueChanged];
        [self.contentSubview addSubview:self.timeSlider];

    }

    -(void)timeValueChanged:(UISlider *)slider
    {
        self.timeValueLabel.text = [NSString stringWithFormat:@"%d min", (int)floorf(slider.value)];
        [self layoutSubviews];
    }
役に立ちましたか?

解決

layoutSubviews Lays out subviews.

- (void)layoutSubviews

Discussion

The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews.

Subclasses can override this method as needed to perform more precise layout of their subviews. You should override this method only if the autoresizing and constraint-based behaviors of the subviews do not offer the behavior you want. You can use your implementation to set the frame rectangles of your subviews directly.

You should not call this method directly. If you want to force a layout update, call the setNeedsLayout method instead to do so prior to the next drawing update. If you want to update the layout of your views immediately, call the layoutIfNeeded method.

Referance by apple doc

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top