gpt4 book ai didi

iphone - 如何垂直移动带有 slider 的 UILabel

转载 作者:行者123 更新时间:2023-11-29 13:14:16 25 4
gpt4 key购买 nike

我想将我的 slider 与我的拇指图像一起垂直移动。但是移动是错误的。

它在水平方向上完美运行,但在垂直方向上运行不佳

- (void)viewDidLoad
{
CGAffineTransform trans = CGAffineTransformMakeRotation(-M_PI * 0.5);
self.SDSlider.transform = trans;
}

- (IBAction)sliderValueChanged:(UISlider *)sender
{
self.SDlabel.text = [NSString stringWithFormat:@"%d", (int)sender.value];

CGRect trackRect = [self.SDSlider trackRectForBounds:self.SDSlider.bounds];
CGRect thumbRect = [self.SDSlider thumbRectForBounds:self.SDSlider.bounds
trackRect:trackRect
value:self.SDSlider.value];

self.testSDlabel.center = CGPointMake(thumbRect.origin.x + self.SDSlider.frame.origin.x, self.SDSlider.frame.origin.y - 20);
self.testSDlabel.text = [NSString stringWithFormat:@"%.0f", self.SDSlider.value];
}

标签从左向右移动,而不是从下往上移动

enter image description here

enter image description here

最佳答案

Got 正在通过更改 center.y 值来工作

- (IBAction)sliderValueChanged:(UISlider *)sender
{
self.SDlabel.text = [NSString stringWithFormat:@"%d", (int)sender.value];


CGRect trackRect = [self.SDSlider trackRectForBounds:self.SDSlider.bounds];
CGRect thumbRect = [self.SDSlider thumbRectForBounds:self.SDSlider.bounds
trackRect:trackRect
value:self.SDSlider.value];

self.SDlabel.text = [NSString stringWithFormat:@"%.0f", self.SDSlider.value];

NSLog(@"thumbRect.origin.x %f",thumbRect.origin.x);
NSLog(@"self.testSDlabel %f",self.SDlabel.center.x);
self.SDlabel.center = CGPointMake(self.SDlabel.center.x, 423 - thumbRect.origin.x);

}

关于iphone - 如何垂直移动带有 slider 的 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16238585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com