Azhar
Azhar

Reputation: 20678

ios : UIScrollView scrolling reset controls position to initials

I am creating a Register screen where if user want to change PIN he should tap on change PIN label and it will add two UITextField Controls (New PIN and Confirm New PIN) after PIN UITextField and push the below fields 100 pixels below.

The problem is when I try to scroll the view to see the below controls it resets the controls (which I moved down) to the initial positions.

ViewDidLoad

[NSTimer scheduledTimerWithTimeInterval:0.1
                                     target:self selector:@selector(forScrollView)userInfo:nil repeats:NO];
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ShowChangePINFields:)];
    singleTap.numberOfTapsRequired = 1;
    _lblChangePIN.userInteractionEnabled = YES;
    [_lblChangePIN addGestureRecognizer:singleTap];

- (void) forScrollView {
    NSLog(@"setScrollEnabled");
    [self.scrollview setScrollEnabled:YES];
    [self.scrollview setContentSize:CGSizeMake(320, 900)]; // must be greater then the size in Storyboard
}// Dispose of any resources that can be recreated.
BOOL isNewPINShow = NO;
    -(void)ShowChangePINFields:(UITapGestureRecognizer *)gestureRecognizer{
        NSLog(@"setScrollEnabled");
        isNewPINShow = NO;
        if(!isNewPINShow)
        {
           // [[self scrollview] setContentOffset:self.scrollview.contentOffset animated:NO];
            _tfNewPIN.hidden = NO;
            _tfConfirmNewPIN.hidden = NO;
            isNewPINShow = YES;


        [UIView animateWithDuration:0.5 animations:^{

            _tfConfirmNewPIN.frame = CGRectMake(306, 197, 292, 30);
            _tfNewPIN.frame = CGRectMake(306, 245, 292, 30);

            CGRect tempFrame = [_tfEmail frame];
            tempFrame.origin.y  = tempFrame.origin.y + 100;
            _tfEmail.frame = tempFrame;                

            tempFrame = [_tfLanguage frame];
            tempFrame.origin.y  = tempFrame.origin.y + 100;
            _tfLanguage.frame = tempFrame;

            tempFrame = [_tfSecretQuestion frame];
            tempFrame.origin.y  = tempFrame.origin.y + 100;
            _tfSecretQuestion.frame = tempFrame;

            tempFrame = [_tfSecretAnswer frame];
            tempFrame.origin.y  = tempFrame.origin.y + 100;
            _tfSecretAnswer.frame = tempFrame;               


        }];
    }
}

Upvotes: 0

Views: 526

Answers (2)

Sruit A.Suk
Sruit A.Suk

Reputation: 7273

you need to move from

Scroll View > All Objects

to

Scroll View > View > All Objects

Below is a sample image

enter image description here

Upvotes: 0

streem
streem

Reputation: 9144

Simply disable "Use Autolayout" in the File Inspector in your storyboard.

Upvotes: 1

Related Questions