0

I'm developing a custom keyboard and I've added the buttons programmatically and they're doing great but when the device rotate the buttons in the bottom disappear -because of the changing of the screen size- so I need to reposition the buttons in new positions -I wanna have four lines instead of six - when the device rotate , how can I do that ?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
keloa zoldik
  • 95
  • 1
  • 15

1 Answers1

0

Try this,

  1. You can use Autoresizing to change position according to size of screen and orientation.
  2. Set custom frame for button

Ex:

your_button.frame=CGRectMake(0,0,100,100) // (x,y,width,height)  
Manikandan D
  • 1,422
  • 1
  • 13
  • 25
  • my problem is how do I know what is the size of the screen I tried to print the width but it didn't work , I tried this code : `print(self.view.frame.width)` – keloa zoldik Oct 01 '15 at 20:13
  • Its Very simple to get screen size: let screenSize: CGRect = UIScreen.mainScreen().bounds; screenSize.origin; let screenWidth = screenSize.width; let screenHeight = screenSize.height; print("The main page width : %f",screenSize.width); print("The main page height : %f",screenSize.height); – Manikandan D Oct 01 '15 at 20:36
  • that's great it worked! but how can I detect when the user rotate his device and reposition the button ? is there a method that works when the user rotate his device ? – keloa zoldik Oct 01 '15 at 21:07
  • If you want to detect screen orientation then ref this answer: http://stackoverflow.com/questions/25666269/ios8-swift-how-to-detect-orientation-change – Manikandan D Oct 01 '15 at 21:08
  • my problem here is that when I use the app I'll know if the user did rotate the device but I'm developing a custom keyboard so that the user can use it in other applications which means that I can't use the AppDelegate for that :( – keloa zoldik Oct 01 '15 at 21:15
  • Can you able to explain about your project? – Manikandan D Oct 01 '15 at 21:31
  • I'm developing a custom keyboard, which means that I'll design a keyboard that can work in any application so you can use the keyboard to write a tweet in twitter or to post a status in Facebook and so on – keloa zoldik Oct 01 '15 at 21:39
  • Great! Then where you go to set your button? – Manikandan D Oct 01 '15 at 21:44
  • sorry I didn't understand you question ^_^! – keloa zoldik Oct 01 '15 at 21:46
  • Okay cool, Tell about button position while rotating.Did you have any image for ref – Manikandan D Oct 01 '15 at 21:48
  • sorry I tried to understand your question but I couldn't , if you're asking how to design a custom keyboard you can see this tutorial : http://www.appcoda.com/custom-keyboard-tutorial/ – keloa zoldik Oct 01 '15 at 22:13