iOS : UIScrollView scrolling reset controls position to initials

标签 ios iphone objective-c uiscrollview

我正在创建一个注册屏幕,如果用户想要更改 PIN,他应该点击更改 PIN 标签,它将在 PIN UITextField 之后添加两个 UITextField 控件(新 PIN 和确认新 PIN),并将以下字段推到下方 100 像素处。

问题是当我尝试 ScrollView 以查看下面的控件时,它会将控件(我向下​​移动)重置为初始位置

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;               


        }];
    }
}

最佳答案

只需在 Storyboard的文件检查器中禁用“使用自动布局”即可。

关于iOS : UIScrollView scrolling reset controls position to initials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22345704/

相关文章:

objective-c - 如何在 XCTest 中提取由 measureBlock 测量的性能指标

iphone - 地址簿中记录的 ABRecordID(地址簿中插入记录的唯一 ID)

ios - 需要从 iOS 中的 tableView 选择动态创建 ViewController 对象

iphone - 如何让 UISearchBar 范围栏始终可见?

ios - 使用 UINavigationController 工具栏的替代方法

iphone - 在 iPod 或 iPhone 中测试我的 ios 应用程序哪个更好?

javascript - iOS 移动应用程序和 Node.js 网络应用程序 AES 256 加密

ios - Objective-C - NSArray 到具有多个定界符的 NSString

ios - kABPersonEmailProperty 返回奇怪的东西

ios - 从 iOS 上传的 SoundCloud 下载文件名不正确