I am developing a custom keyboard for iOS.
We are struggling with the automatic resolution of each model.
let screenSize=UISscreen.mainScreen().bounds.size
Obtain the screen size in
Based on the screen size, calculate the display area of the keyboard, the width of the key, etc., and
I draw the keyboard without using Interface Builder, but
It's okay with the new app, but
When the keyboard appears in an old app,
Auto-scaling can increase the size (probably approximately 1.17 times) and
As shown in the image below, the right side of the keyboard overflows from the screen, causing a key not to appear.
The trouble is that even if it is automatically enlarged, if you get the width of the screenSize above, it will return a value of 375 to match the size of the iPhone 6 and not return the original screen width of 320.
(If you could give me 320 back, I could easily recalculate it.)
So I have a question,
Is there a way to get the actual image resolution before auto-scaling?
It didn't work even if I did it in viewDidLoad.
Or is there any other good solution?
For example, I rarely use constraints, so I wonder if I can solve this problem if I use them.
(Currently, almost everything is displayed in a program, and I don't use constraints.)
I'm afraid it might be a rudimentary question, but
If anyone knows, I would appreciate it if you could let me know.
A rough implementation of the code is similar to the following:
// Get screen size
myAppFrameSize=UISscreen.mainScreen().bounds
print(myAppFrameSize!.width)
screenWidth = myAppFrameSize!.width
screenHeight=myAppFrameSize!.height
isPortlayit=screenWidth>screenHeight?false:true//Verifying the Screen Direction
isIPad=screenWidth>900?true:false
if(isIPad){
keyWidth = 100
} else if (screenWidth <900&&screenWidth > 370) {
keyWidth = 55
} else {
keyWidth = 48
}
See self.view.bounds
in viewDidLayoutSubviews
.
The first (when viewDidLoad
or viewWillAppear
is called) will be the size (width=375) before viewDidAppear
is called, but just before viewDidAppear
is called, the size (width=320) should be taken.
© 2024 OneMinuteCode. All rights reserved.