我正在使用此代码为我的所有设备正确设置位置。我遇到的问题是,如果我在4s中设置滑块的位置,则iphone 6+位置会发生变化。我的其他设备也一样。如何让每台设备完美定位滑块?我在spritekit btw。
//iphone4s
if UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.maxLength < 568.0 {
middleSlider = UISlider(frame: CGRectMake(180, 50, 150, 20))
middleSlider.tintColor = UIColor.whiteColor()
middleSlider.setThumbImage(UIImage(named: "thumb2"), forState: UIControlState.Normal)
self.view?.addSubview(middleSlider)
bottomAudioControlBg.position = CGPointMake(self.size.width / 2, self.size.height / 7)
}
//iphone5
if UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.maxLength == 568.0 {
}
//iphone6
if UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.maxLength == 667.0 {
}
//iphone6+
if UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.maxLength == 736.0 {
middleSlider = UISlider(frame: CGRectMake(255, 50, 150, 20))
middleSlider.tintColor = UIColor.whiteColor()
middleSlider.setThumbImage(UIImage(named: "thumb2"), forState: UIControlState.Normal)
self.view?.addSubview(middleSlider)
}
//ipad
if UIDevice.currentDevice().userInterfaceIdiom == .Pad && ScreenSize.maxLength == 1024.0 {
}
//ipadpro
if UIDevice.currentDevice().userInterfaceIdiom == .Pad && ScreenSize.maxLength == 1366.0 {
}
答案 0 :(得分:1)
这是解决此类问题的方法:)
使用简单的缩放因子,您可以轻松解决此问题:
let scaleFactor = UIScreen.mainScreen().bounds.width / 320
let middleSlider = UISlider(frame: CGRectMake(180 * scaleFactor, 50, 150, 20))
middleSlider.tintColor = UIColor.whiteColor()
middleSlider.setThumbImage(UIImage(named: "thumb2"), forState: UIControlState.Normal)
self.view?.addSubview(middleSlider)