UITextField cursor position change on orientation change
Asked Answered
R

2

7

Working fine with iOS6 even if I change the orientation Working fine with iOS6

Working fine with iOS7 If I don't change the orientation Working fine with iOS7

Error in display when orientation gets change iOS7.* Error in display when orientation gets change iOS7

I am creating UITextField programmatically, its working fine with < iOS7,

with iOS7 and higher , when I change orientation UITextField cursor position gets change. What's the issue? Is it bug of iOS?

The rounded corners UITextField you're seeing is UITextField only, I just make it rounded by setting corner of UITextField.

I've set left and right view of UITextField. Also in orientation changes method I'm not even touching that UITextField.

Update:

I find that there's contentOffset changes in UIFieldEditor subview of UITextField

- (void)resizeUITextFieldInsideUITextFieldWithOffset:(CGFloat)y {
    for(id subview in [txtSearch subviews]) {
        if([subview isKindOfClass:[UIScrollView class]]) {
            UIScrollView *textField = (UIScrollView *)subview;
            [textField setContentOffset:CGPointMake(0, y)];
        }
    }
}

I fix it using the above code in orientation, but when I type again the same problem occurring again.

Ravelin answered 10/4, 2014 at 12:0 Comment(0)
T
8

Changing the uiviwcontroller's enter image description here fixed the issue for me, random bug.

enter image description here

Tosspot answered 3/7, 2014 at 19:27 Comment(1)
I can confirm that, even after 4 years of asking this question this solution is still working for me :DRavelin
A
1

Try to resign it when you are going to rotate and again put as first responder as soon as you finish rotating it. I don't actually why it happens but this should make the try. Do you have autolayout set?

Antediluvian answered 14/4, 2014 at 12:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.