我正在创建一个注册屏幕,如果用户想要更改 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/