It seems like 0.07 ofxiPhoneKeyboard isn’t working right with OFXIPHONE_ORIENTATION_LANDSCAPE_LEFT or OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT; it’s drawing way off from where it should be, and is not oriented correctly.
Here’s another iteration on ofxiPhoneKeyboard.mm changes, at 3 places in that file:
- (id) init:(int)x y:(int)y width:(int)w height:(int)h
{
if(self = [super init])
{
_textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, w, h)];
switch (ofxiPhoneGetOrientation())
{
case OFXIPHONE_ORIENTATION_LANDSCAPE_LEFT:
_textField.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
case OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT:
_textField.transform = CGAffineTransformMakeRotation(-M_PI_2);
break;
case OFXIPHONE_ORIENTATION_UPSIDEDOWN:
_textField.transform = CGAffineTransformMakeRotation(M_PI);
break;
default:
break;
}
(...)
- (void) updateOrientation
{
_textField.transform = CGAffineTransformMakeRotation(0.0f);
[self setFrame:CGRectMake(0,0,_w,_h)];
switch (ofxiPhoneGetOrientation())
{
case OFXIPHONE_ORIENTATION_LANDSCAPE_LEFT:
_textField.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
case OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT:
_textField.transform = CGAffineTransformMakeRotation(-M_PI_2);
break;
case OFXIPHONE_ORIENTATION_PORTRAIT:
_textField.transform = CGAffineTransformMakeRotation(0.0f);
break;
case OFXIPHONE_ORIENTATION_UPSIDEDOWN:
_textField.transform = CGAffineTransformMakeRotation(M_PI);
break;
default:
break;
}
(...)
- (void) setFrame: (CGRect) rect
{
CGSize s = [[[UIApplication sharedApplication] keyWindow] bounds].size;
switch (ofxiPhoneGetOrientation())
{
case OFXIPHONE_ORIENTATION_LANDSCAPE_LEFT:
[_textField setFrame: CGRectMake(s.width - rect.origin.y - rect.size.height, rect.origin.x, rect.size.height, rect.size.width)];
break;
case OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT:
[_textField setFrame: CGRectMake(rect.origin.y, s.height - rect.origin.x - rect.size.width, rect.size.height, rect.size.width)];
break;
case OFXIPHONE_ORIENTATION_UPSIDEDOWN:
[_textField setFrame: CGRectMake(s.width - rect.origin.x - rect.size.width, s.height - rect.origin.y - rect.size.height, rect.size.width, rect.size.height)];
break;
default:
[_textField setFrame: CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];
}
}
This works for me in all 4 orientations. An easy way to test it is to set the orientation in KeyboardExample and see if it still draws in the upper-left of the screen.
In KeyboardExample’s testapp.mm:
void testApp::setup(){
// register touch events
ofRegisterTouchEvents(this);
iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);
(...)
I would also suggest changing the KeyboardExample keyboard values to something like:
keyboard = new ofxiPhoneKeyboard(0,20,320,32);
The 0.07 ofxiPhoneKeyboard.mm is for some reason setting the top of the rect to the requested y + height instead of just y, which seemed strange. The ofxiPhoneKeyboard.mm changes above fix this.