通过更改UISlider来调整两个UIViews的大小

时间:2013-09-24 06:27:34

标签: ios objective-c uiview split

我正在尝试创建一个应用程序(对于ipad),它可以显示两个彼此相邻的视图,并且可以通过UISlider调整大小,只需将Value从0更改为屏幕宽度(1024)就像这样

enter image description here

width = 512,这使得主视图分为两个视图,一个等于另一个视图 我的问题是如何通过UISlider用户调整这些视图的大小 我试过这个

viewResizerUISlider

- (IBAction)valueChanged:(id)sender {
    if (self.viewResizer.value >512) {
        [self.secView setFrame:CGRectMake(self.secView.frame.origin.x, self.secView.frame.origin.y,self.viewResizer.value , 660.0)];
        [self.firstView setFrame:CGRectMake(orgiX, orgiY,self.secView.frame.size.width- self.viewResizer.value , 660)];
    }else{

    }    
}

1 个答案:

答案 0 :(得分:0)

如果你的滑块例如有1024个值,那么你可以:

- (IBAction)valueChanged:(id)sender 
{
    //First view will be resized from 0 to sliders value, 
    [self.firstView setFrame:CGRectMake(0, 0, sender.value, 660)];

    //Second view will be resized from first views width, to 1024(parent view width)-first views width.
    [self.secView setFrame:CGRectMake(self.firstView.frame.size.width, 0, self.view.frame.size.width - self.firstView.frame.size.width, 660)];
}

然后你可以将滑块值减少到256(但是它不会那么平滑):

- (IBAction)valueChanged:(id)sender 
{
    //First view will be resized from 0 to sliders value, 
    [self.firstView setFrame:CGRectMake(0, 0, sender.value*4, 660)];

    //Second view will be resized from first views width, to 1024(parent view width)-first views width.
    [self.secView setFrame:CGRectMake(self.firstView.frame.size.width, 0, self.view.frame.size.width - self.firstView.frame.size.width, 660)];
}