为什么滑块消失了?
这是我用来绘制自定义滑块的代码,但当我开始拖动它时它消失了。
-(void)addSliderX:frame andminimumValue:(int)min andmaximumValue:(int)max andSliderValue:(int)value{
CGRect frame1 = CGRectFromString(frame);
statSlider = [[UISlider alloc]initWithFrame:frame1];
//[statSlider setMinimumTrackImage:[[UIImage imageNamed:@"greenSlider.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:10.0] forState:UIControlStateNormal];
[statSlider setMinimumTrackImage:[[UIImage imageNamed:@"sliderBar_green_stretch.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[statSlider setMaximumTrackImage:[[UIImage imageNamed:@"sliderBar_brown_stretch.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[statSlider setThumbImage:[UIImage imageNamed:@"sliderBar_greenThumb.png"] forState:UIControlStateNormal];
[statSlider setMinimumValue:min];
[statSlider setMaximumValue:max];
statSlider.continuous = NO;
positionX = value;
UIFont * font = YEAR_LABEL_FONT;
[statSlider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
[statSlider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventTouchUpInside];
UIView * bubble2 = [[UIView alloc]init];
UIImageView * back2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"sliderBar_handle_number.png"]];
UILabel * val = [[UILabel alloc]init];
UIButton * newB = [ApplicationHelpers buttonWithTitle:@"" andBgColor:[UIColor clearColor] andTitleColor:DESC_Color_White andTitleFont:font];
UIImage *buttonImage2 = [UIImage imageNamed:@"sliderBar_handle_number.png"];
UIImage *strechableButtonImage2 = [buttonImage2 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[newB setBackgroundImage:strechableButtonImage2 forState:UIControlStateNormal];
bubble2.tag = viewTag +1;
back2.tag = viewTag + 2;
val.tag = viewTag + 3;
newB.tag = viewTag + 4;
/*bubble2.alpha = 0;
back2.alpha = 0;
val.alpha = 0;*/
bubble2.hidden = YES;
back2.hidden = YES;
val.hidden = YES;
[self.view addSubview:statSlider];
//[self.view addSubview:bubble2];
[self.view addSubview:newB];
[bubble2 addSubview:back2];
[bubble2 addSubview:val];
}
// create the bubble over slider
-(void)valueChanged:(id)sender{
UISlider *localSlider = (UISlider *)sender;
greenSliderValue = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%3.0f", [localSlider value]]];
dsp =[greenSliderValue floatValue];
UIView * bubble2 = (UIView*)[self.view viewWithTag:151186];
UIButton * newB = (UIButton*)[self.view viewWithTag:151189];
UIImageView * back2 = (UIImageView*)[bubble2 viewWithTag:151187];
UILabel * val = (UILabel*)[bubble2 viewWithTag:151188];
NSString *valString = [NSString stringWithFormat:@"%3.0f", [localSlider value]];
[val setText:valString];
[newB setTitle:valString forState:UIControlStateNormal];
[newB setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
UIFont * font = YEAR_LABEL_FONT;
val.font = font;
val.textColor = DESC_Color_White;
bubble2.hidden = NO;
back2.hidden = NO;
val.hidden = NO;
newB.hidden = NO;
CGFloat sliderMax = localSlider.maximumValue;
CGFloat sliderMin = localSlider.minimumValue;
CGFloat sliderMaxMinDiff = sliderMax - sliderMin;
CGFloat sliderValue = dsp;
CGFloat xCoord = 65.0-42.0;
CGFloat yCoord = (CGFloat)positionX;
CGFloat halfMax = (sliderMax+sliderMin)/2.0;
if (sliderValue > halfMax)
{
xCoord = xCoord-(sliderValue-halfMax);
}
else
{
xCoord = xCoord + (halfMax-sliderValue);
}
xCoord= xCoord + (600/sliderMaxMinDiff)*(sliderValue-sliderMin);
newB.frame = CGRectMake(xCoord,yCoord,84,47);
}
// Gets activated when slider is moved
-(void)sliderChanged:(id)sender{
i = i+1;
UISlider *localSlider = (UISlider *)sender;
greenSliderValue = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%3.0f", [localSlider value]]];
dsp =[greenSliderValue floatValue];
currentDict = [[totalDict objectForKey:[[totalDict objectForKey:@"Screens"]objectAtIndex:i]]retain];
NSString * identifier = [currentDict objectForKey:@"identifier"];
if ([identifier isEqualToString:@"end"]) {
NSDictionary * completed = [currentDict objectForKey:@"Completed"];
NSString * frameD = [completed objectForKey:@"Frame"];
CGRect frame3 = CGRectFromString(frameD);
NSString * frameString2 = NSStringFromCGRect(frame3);
NSString * label = [completed objectForKey:@"Dest"];
[self doneButtons:label andFrame:frameString2];
[sliderBox removeFromSuperview];
[yes removeFromSuperview];
[no removeFromSuperview];
[next removeFromSuperview];
[statSlider removeFromSuperview];
[self estimateButtons:@" Estimate." andFrameX:509 andFrameY:520 andFrameW:234 andFrameH:54];
}
else {
NSDictionary * quest = [currentDict objectForKey:@"Question"];
NSString * text = [quest objectForKey:@"Text"];
NSString * frameQ = [quest objectForKey:@"Frame"];
CGRect frame1 = CGRectFromString(frameQ);
NSString * frameString = NSStringFromCGRect(frame1);
if ([identifier isEqualToString:@"Yes"])
{
NSDictionary * selectable1 = [currentDict objectForKey:@"Selectable1"];
NSString * frameYes = [selectable1 objectForKey:@"Frame"];
CGRect frame3 = CGRectFromString(frameYes);
NSString * frameString3 = NSStringFromCGRect(frame3);
NSDictionary * selectable2 = [currentDict objectForKey:@"Selectable2"];
NSString * frameNo = [selectable2 objectForKey:@"Frame"];
CGRect frame4 = CGRectFromString(frameNo);
NSString * frameString4 = NSStringFromCGRect(frame4);
select.hidden = YES;
[yes removeFromSuperview];
[no removeFromSuperview];
[self yesButton:@" Yes." andFrame:frameString3];
[self noButton:@" No." andFrame:frameString4];
}
else
{
NSDictionary * selectable = [currentDict objectForKey:@"Selectable"];
NSString * frameBu = [selectable objectForKey:@"Frame"];
CGRect frame2 = CGRectFromString(frameBu);
NSString * frameString1 = NSStringFromCGRect(frame2);
select.hidden = YES;
[self selectButtons:@" Select." andFrame:frameString1 andValue:goal];
}
NSDictionary * completed = [currentDict objectForKey:@"Completed"];
NSString * frameD = [completed objectForKey:@"Frame"];
CGRect frame3 = CGRectFromString(frameD);
NSString * frameString2 = NSStringFromCGRect(frame3);
NSString * label = [completed objectForKey:@"Dest"];
UIView * bubble2 = (UIView*)[self.view viewWithTag:1];
UIButton * newB = (UIButton*)[self.view viewWithTag:151189];
[newB removeFromSuperview];
[bubble2 removeFromSuperview];
[greenSliderValue release];
[statSlider removeFromSuperview];
[trade removeFromSuperview];
[sliderBox removeFromSuperview];
[slidValue removeFromSuperview];
[next removeFromSuperview];
[self question:text andFrame:frameString];
[self doneButtons:label andFrame:frameString2];
}
}
Here's the code i am using to draw a custom slider but its disappearing when i started dragging it.
-(void)addSliderX:frame andminimumValue:(int)min andmaximumValue:(int)max andSliderValue:(int)value{
CGRect frame1 = CGRectFromString(frame);
statSlider = [[UISlider alloc]initWithFrame:frame1];
//[statSlider setMinimumTrackImage:[[UIImage imageNamed:@"greenSlider.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:10.0] forState:UIControlStateNormal];
[statSlider setMinimumTrackImage:[[UIImage imageNamed:@"sliderBar_green_stretch.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[statSlider setMaximumTrackImage:[[UIImage imageNamed:@"sliderBar_brown_stretch.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[statSlider setThumbImage:[UIImage imageNamed:@"sliderBar_greenThumb.png"] forState:UIControlStateNormal];
[statSlider setMinimumValue:min];
[statSlider setMaximumValue:max];
statSlider.continuous = NO;
positionX = value;
UIFont * font = YEAR_LABEL_FONT;
[statSlider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
[statSlider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventTouchUpInside];
UIView * bubble2 = [[UIView alloc]init];
UIImageView * back2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"sliderBar_handle_number.png"]];
UILabel * val = [[UILabel alloc]init];
UIButton * newB = [ApplicationHelpers buttonWithTitle:@"" andBgColor:[UIColor clearColor] andTitleColor:DESC_Color_White andTitleFont:font];
UIImage *buttonImage2 = [UIImage imageNamed:@"sliderBar_handle_number.png"];
UIImage *strechableButtonImage2 = [buttonImage2 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[newB setBackgroundImage:strechableButtonImage2 forState:UIControlStateNormal];
bubble2.tag = viewTag +1;
back2.tag = viewTag + 2;
val.tag = viewTag + 3;
newB.tag = viewTag + 4;
/*bubble2.alpha = 0;
back2.alpha = 0;
val.alpha = 0;*/
bubble2.hidden = YES;
back2.hidden = YES;
val.hidden = YES;
[self.view addSubview:statSlider];
//[self.view addSubview:bubble2];
[self.view addSubview:newB];
[bubble2 addSubview:back2];
[bubble2 addSubview:val];
}
// create the bubble over slider
-(void)valueChanged:(id)sender{
UISlider *localSlider = (UISlider *)sender;
greenSliderValue = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%3.0f", [localSlider value]]];
dsp =[greenSliderValue floatValue];
UIView * bubble2 = (UIView*)[self.view viewWithTag:151186];
UIButton * newB = (UIButton*)[self.view viewWithTag:151189];
UIImageView * back2 = (UIImageView*)[bubble2 viewWithTag:151187];
UILabel * val = (UILabel*)[bubble2 viewWithTag:151188];
NSString *valString = [NSString stringWithFormat:@"%3.0f", [localSlider value]];
[val setText:valString];
[newB setTitle:valString forState:UIControlStateNormal];
[newB setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
UIFont * font = YEAR_LABEL_FONT;
val.font = font;
val.textColor = DESC_Color_White;
bubble2.hidden = NO;
back2.hidden = NO;
val.hidden = NO;
newB.hidden = NO;
CGFloat sliderMax = localSlider.maximumValue;
CGFloat sliderMin = localSlider.minimumValue;
CGFloat sliderMaxMinDiff = sliderMax - sliderMin;
CGFloat sliderValue = dsp;
CGFloat xCoord = 65.0-42.0;
CGFloat yCoord = (CGFloat)positionX;
CGFloat halfMax = (sliderMax+sliderMin)/2.0;
if (sliderValue > halfMax)
{
xCoord = xCoord-(sliderValue-halfMax);
}
else
{
xCoord = xCoord + (halfMax-sliderValue);
}
xCoord= xCoord + (600/sliderMaxMinDiff)*(sliderValue-sliderMin);
newB.frame = CGRectMake(xCoord,yCoord,84,47);
}
// Gets activated when slider is moved
-(void)sliderChanged:(id)sender{
i = i+1;
UISlider *localSlider = (UISlider *)sender;
greenSliderValue = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%3.0f", [localSlider value]]];
dsp =[greenSliderValue floatValue];
currentDict = [[totalDict objectForKey:[[totalDict objectForKey:@"Screens"]objectAtIndex:i]]retain];
NSString * identifier = [currentDict objectForKey:@"identifier"];
if ([identifier isEqualToString:@"end"]) {
NSDictionary * completed = [currentDict objectForKey:@"Completed"];
NSString * frameD = [completed objectForKey:@"Frame"];
CGRect frame3 = CGRectFromString(frameD);
NSString * frameString2 = NSStringFromCGRect(frame3);
NSString * label = [completed objectForKey:@"Dest"];
[self doneButtons:label andFrame:frameString2];
[sliderBox removeFromSuperview];
[yes removeFromSuperview];
[no removeFromSuperview];
[next removeFromSuperview];
[statSlider removeFromSuperview];
[self estimateButtons:@" Estimate." andFrameX:509 andFrameY:520 andFrameW:234 andFrameH:54];
}
else {
NSDictionary * quest = [currentDict objectForKey:@"Question"];
NSString * text = [quest objectForKey:@"Text"];
NSString * frameQ = [quest objectForKey:@"Frame"];
CGRect frame1 = CGRectFromString(frameQ);
NSString * frameString = NSStringFromCGRect(frame1);
if ([identifier isEqualToString:@"Yes"])
{
NSDictionary * selectable1 = [currentDict objectForKey:@"Selectable1"];
NSString * frameYes = [selectable1 objectForKey:@"Frame"];
CGRect frame3 = CGRectFromString(frameYes);
NSString * frameString3 = NSStringFromCGRect(frame3);
NSDictionary * selectable2 = [currentDict objectForKey:@"Selectable2"];
NSString * frameNo = [selectable2 objectForKey:@"Frame"];
CGRect frame4 = CGRectFromString(frameNo);
NSString * frameString4 = NSStringFromCGRect(frame4);
select.hidden = YES;
[yes removeFromSuperview];
[no removeFromSuperview];
[self yesButton:@" Yes." andFrame:frameString3];
[self noButton:@" No." andFrame:frameString4];
}
else
{
NSDictionary * selectable = [currentDict objectForKey:@"Selectable"];
NSString * frameBu = [selectable objectForKey:@"Frame"];
CGRect frame2 = CGRectFromString(frameBu);
NSString * frameString1 = NSStringFromCGRect(frame2);
select.hidden = YES;
[self selectButtons:@" Select." andFrame:frameString1 andValue:goal];
}
NSDictionary * completed = [currentDict objectForKey:@"Completed"];
NSString * frameD = [completed objectForKey:@"Frame"];
CGRect frame3 = CGRectFromString(frameD);
NSString * frameString2 = NSStringFromCGRect(frame3);
NSString * label = [completed objectForKey:@"Dest"];
UIView * bubble2 = (UIView*)[self.view viewWithTag:1];
UIButton * newB = (UIButton*)[self.view viewWithTag:151189];
[newB removeFromSuperview];
[bubble2 removeFromSuperview];
[greenSliderValue release];
[statSlider removeFromSuperview];
[trade removeFromSuperview];
[sliderBox removeFromSuperview];
[slidValue removeFromSuperview];
[next removeFromSuperview];
[self question:text andFrame:frameString];
[self doneButtons:label andFrame:frameString2];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在 -(void)sliderChanged:(id)sender 中的“[sliderBox removeFromSuperview]”上放置了断点并检查它们是否被击中? - 这似乎可能会导致滑块从容器视图中删除。
Have you put break points on "[sliderBox removeFromSuperview]" in -(void)sliderChanged:(id)sender and checked if they are getting hit? - that seems like it could cause the removal of the slider from your container view.