iphone - Keep UIScrollView in correct place after switching from landscape to portrait -


i have uiscrollview contains text field , text view. have code move text fields when keyboard present keyboard not cover text fields. code works great in portrait view:

-(bool)textfieldshouldreturn:(uitextfield *)textfield {     if(textfield) {         [textfield resignfirstresponder];     }     return no; }  -(void)textfielddidbeginediting:(uitextfield *)textfield {     if (textfield == self.namefield) {         [uiview beginanimations:nil context:null];         [uiview setanimationdelegate:self];         [uiview setanimationduration:0.3];         [uiview setanimationbeginsfromcurrentstate:yes];         self.view.frame = cgrectmake(self.view.frame.origin.x,   (self.view.frame.origin.y - 90), self.view.frame.size.width, self.view.frame.size.height);         [uiview commitanimations];     } }  -(void)textfielddidendediting:(uitextfield *)textfield {     if (textfield == self.namefield) {         [uiview beginanimations:nil context:null];         [uiview setanimationdelegate:self];         [uiview setanimationduration:0.3];         [uiview setanimationbeginsfromcurrentstate:yes];         self.view.frame = cgrectmake(self.view.frame.origin.x, (self.view.frame.origin.y + 90), self.view.frame.size.width, self.view.frame.size.height);         [uiview commitanimations];     } }  -(void)textviewdidbeginediting:(uitextview *)textfield {     if (textfield == self.questionfield) {         [uiview beginanimations:nil context:null];         [uiview setanimationdelegate:self];         [uiview setanimationduration:0.3];         [uiview setanimationbeginsfromcurrentstate:yes];         self.view.frame = cgrectmake(self.view.frame.origin.x, (self.view.frame.origin.y - 200), self.view.frame.size.width, self.view.frame.size.height);         [uiview commitanimations];     } }  -(void)textviewshouldendediting:(uitextview *)textfield {     if (textfield == self.questionfield) {         [uiview beginanimations:nil context:null];         [uiview setanimationdelegate:self];         [uiview setanimationduration:0.3];         [uiview setanimationbeginsfromcurrentstate:yes];         uiinterfaceorientation interfaceorientation = self.interfaceorientation;          self.view.frame = cgrectmake(self.view.frame.origin.x, (self.view.frame.origin.y + 200), self.view.frame.size.width, self.view.frame.size.height);         [uiview commitanimations];     } } 

when rotate iphone simulator landscape view, (not surprisingly) not work. how can text field move enough see while typing in both landscape , portrait views?

also, if rotate landscape portrait while keyboard shown, after dismissing keyboard scroll view has moved down screen instead of lined in original position. how can avoid this?

apple's document managing keyboard shows proper way under heading "moving content located under keyboard".

you put content on scroll view , use uikeyboarddidshownotification , uikeyboardwillhidenotification notifications adjust content offsets.

however, code incomplete. keyboard size calculation doesn't work in landscape mode. fix it, replace this:

cgsize kbsize = [[info objectforkey:uikeyboardframebeginuserinfokey] cgrectvalue].size; 

with this:

// works in both portrait , landscape mode cgrect kbrect = [[info objectforkey:uikeyboardframebeginuserinfokey] cgrectvalue]; kbrect = [self.view convertrect:kbrect toview:nil];  cgsize kbsize = kbrect.size; 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -