2016-04-08 3 views
0

このコードを使用して、すべてのマイデバイスの位置を正しく設定します。私がスライダーの位置を4秒間に設定すると、iPhone 6+の位置が変わるという問題があります。私の他のデバイスにも同じことが起こります。すべてのデバイスにスライダを完全に配置させるにはどうすればよいですか?私はspritekit btwですべてのデバイスでspritekit内のUISliderの位置を設定できませんでしたか?

//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 { 

} 

答えて

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) 
+0

大丈夫それが動作します。ありがとうございました! – coding22

+0

私は1つの質問をipadのためにもこの仕事はありますか? – coding22

+0

私はipadのためにそれを試して、スライダは、iphoneのような正しい位置にありません。 – coding22

関連する問題