我想适应的UIButton所有iPhone屏幕的大小,距离:如何关系计算到窗口
- iPhone 4S
- iPhone 5
- iPhone 5S
- iPhone 6S加
我如何计算距离与屏幕尺寸的关系?
我需要适合所有iPhone屏幕的暂停按钮和录制按钮。
实际上,它在iPhone 6上看到完美,但在iPhone 6上加上它看起来非常不同。
我不使用故事板!我只需要使用代码就非常重要!
iPhone 6:
iPhone 6加:
GameViewController:
暂停按钮:
func addPauseButton() {
//create Pause Button
PauseButton = UIButton.init(frame: CGRectMake(self.view!.frame.size.width/2 + 150,self.view!.frame.size.height/2 - 315 ,30,30))
PauseButton.setImage(UIImage(named: "Pause-Button.png"), forState: UIControlState.Normal)
PauseButton.addTarget(self, action: "pressedPauseGame:", forControlEvents: .TouchUpInside)
self.view.addSubview(PauseButton)
}
录制按钮:
func addRecordButton() {
startRecordingButton = UIButton.init(frame: CGRectMake(self.view!.frame.size.width/2 + 155 ,self.view!.frame.size.height/2 - 275 ,25,25))
startRecordingButton.setImage(UIImage(named: "Record-Off.png"), forState: UIControlState.Normal)
startRecordingButton.addTarget(self, action: "startRecordingButtonTapped:", forControlEvents: .TouchUpInside)
self.view.addSubview(startRecordingButton)
stopRecordingButton = UIButton.init(frame: CGRectMake(self.view!.frame.size.width/2 + 155 ,self.view!.frame.size.height/2 - 275 ,25,25))
stopRecordingButton.setImage(UIImage(named: "Record-On.png"), forState: UIControlState.Normal)
stopRecordingButton.addTarget(self, action: "stopRecordingButtonTapped:", forControlEvents: .TouchUpInside)
self.view.addSubview(stopRecordingButton)
}
你说你不能使用自动布局,因为Sprite Kit(阅读评论)? https://github.com/mgrebenets/SpriteKitAutoLayout – tktsubota