Thursday 15 April 2010

ios - Custom keyboard height doesn't change when device orientation changes -



ios - Custom keyboard height doesn't change when device orientation changes -

whenever rotate device, custom keyboard height remains same. seek remove constraints , add together 1 time again no luck. have looked @ lots of related question on stack overflow , on ios dev forum still haven't solution..

i read used app -(void)viewdidappear:(bool)animated 1 time set size using code:

-(void)viewdidappear:(bool)animated { [super viewdidappear:animated]; [self updatecustomheight]; } -(void)updatecustomheight { [self updateviewconstraints]; cgfloat _expandedheight = 250; nslayoutconstraint *_heightconstraint = [nslayoutconstraint constraintwithitem:self.view attribute:nslayoutattributeheight relatedby:nslayoutrelationequal toitem:nil attribute:nslayoutattributenotanattribute multiplier:0.0 constant:_expandedheight]; [self.view removeconstraint: _heightconstraint]; [self.view layoutifneeded]; if(isportrait) { cgfloat _expandedheight = 230; nslayoutconstraint *_heightconstraint = [nslayoutconstraint constraintwithitem:self.view attribute:nslayoutattributeheight relatedby:nslayoutrelationequal toitem:nil attribute:nslayoutattributenotanattribute multiplier:0.0 constant: _expandedheight]; [self.view addconstraint: _heightconstraint]; } else { cgfloat _expandedheight = 200; nslayoutconstraint *_heightconstraint = [nslayoutconstraint constraintwithitem:self.view attribute:nslayoutattributeheight relatedby:nslayoutrelationequal toitem:nil attribute:nslayoutattributenotanattribute multiplier:0.0 constant: _expandedheight]; [self.view addconstraint: _heightconstraint]; } }

but when ever load custom keyboard setting first time setter frame display landscape portrait orientation.

portrait:

landscape:

i calling alter size method when orientation alter delegate:

-(void)willrotatetointerfaceorientation:(uiinterfaceorientation)tointerfaceorientation duration:(nstimeinterval)duration { if([uiscreen mainscreen].bounds.size.width < [uiscreen mainscreen].bounds.size.height){ //keyboard in portrait isportrait=yes; [self loadkeyboardview]; [self updatecustomheight]; } else{ isportrait=no; [self loadkeyboardview]; [self updatecustomheight]; //keyboard in landscape } }

note:

for keyboard layout using xib , load nib par device orientation working fine update of size in device orientation wont working. please help me on this

when add together height constraint need maintain in property can subsequently remove it.

@property (strong,nonatomic) nslayoutconstraint *heightconstraint; -(void)updatecustomheight { [self updateviewconstraints]; cgfloat expandedheight = 250; if (self.heightconstraint != nil) { [self.view removeconstraint:self.heightconstraint]; [self.view layoutifneeded]; if(isportrait) { expandedheight = 230; } else { expandedheight = 200; } self.heightconstraint = [nslayoutconstraint constraintwithitem:self.view attribute:nslayoutattributeheight relatedby:nslayoutrelationequal toitem:nil attribute:nslayoutattributenotanattribute multiplier:0.0 constant: expandedheight]; [self.view addconstraint:self.heightconstraint]; [self.view layoutifneeded]; }

ios iphone custom-keyboard ios8-extension ios-keyboard-extension

No comments:

Post a Comment