好的,我昨天问了这个问题,但我更新了它,并提供了有关我遇到的问题的更多详细信息。我遇到的问题是这样的。当我运行我的应用程序时,主视图看起来很好,就像它应该的那样。但是,当我单击按钮转到下一个 View 时,该 View 会向上移动约 20 像素。当我返回主屏幕时,它会向上移动相同的位置。
我的应用程序看起来像它应该的唯一一次是当我第一次加载它时,一旦我单击按钮并开始更改 View ,我离开主视图后的每个 View 第一次都会向上移动 20 像素,甚至当我回到主视图时。当我从 xcode 3.2 升级到 xcode 4.0 beta 时,我开始遇到这个问题。我发现有一种切换 View 的方法不会使 View 向上移动,但是,我对这种方式有疑问。我让用户在 view1 上输入数据,单击按钮,它会切换到 view2 并将数据从 1 发送到 2。使用 switchview 方法显示我的 View ,因为它们应该是我的数据,但不想传输到 view2。使用 switchview 方法可以将数据从我需要的 1 传输到 2,它将 View 向上移动 20 个像素。以下是我使用的示例。
- 在 xcode 4 中,这种方式会导致我的视图向上移动 20 个像素,而在 xcode 3.25 中,它工作得很好,没有任何问题,并且它将数据从 view1 传输到 view2。
- (IBAction)calculate:(id)sender {
MaleResultsController *maleResults = [[MaleResultsController alloc] initWithNibName:@"MaleResultsController" bundle:nil];
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.view cache:YES];
[self.view addSubview:maleResults.view];
maleResults.displayAge.text = ageInput.text;
maleResults.displayHeight.text = heightInput.text;
maleResults.displayWeight.text = weightInput.text;
NSString *minWeightString = [[NSString alloc] initWithFormat:@"%.0f", [self getMinWeight]];
maleResults.displayMinWeight.text = minWeightString;
[minWeightString release];
NSString *maxWeightString = [[NSString alloc] initWithFormat:@"%.0f", [self getMaxWeight]];
maleResults.displayMaxWeight.text = maxWeightString;
[maxWeightString release];
NSString *maxBodyFatString = [[NSString alloc] initWithFormat:@"%.0f", [self getMaxBodyFatPercentage]];
maleResults.displayMaxBodyFatPercentage.text = maxBodyFatString;
[maxBodyFatString release];
NSString *bodyFatString = [[NSString alloc] initWithFormat:@"%.0f", [self getBodyFatPercentage]];
maleResults.displayBodyFat.text = bodyFatString;
[bodyFatString release];
NSString *abdomenAvgString = [[NSString alloc] initWithFormat:@"%.2f", [self getAbdomenAvg]];
maleResults.abdomenAvg.text = abdomenAvgString;
[abdomenAvgString release];
NSString *neckAvgString = [[NSString alloc] initWithFormat:@"%.2f", [self getNeckAvg]];
maleResults.neckAvg.text = neckAvgString;
[neckAvgString release];
NSString *abNeckFactorString = [[NSString alloc] initWithFormat:@"%.2f", [self getAbNeckFactor]];
maleResults.abdomenNeckFactor.text = abNeckFactorString;
[abNeckFactorString release];
//
// [self.navigationController pushViewController:maleResults animated:YES];
[UIView commitAnimations];
}
-- 在 xcode 4 中,此方法可以正确切换 View ,但不会将 view1 上的文本字段输入传输到 view2 上的标签输出。
- (IBAction)calculate:(id)sender {
MaleBFCResults *maleBFCresults = [[MaleBFCResults alloc] initWithNibName:@"MaleBFCResults" bundle:nil];
MaleBFCdata *maleBFCData = [[MaleBFCdata alloc] init];
maleBFCresults.maleData = maleBFCData;
maleBFCresults.displayAge = ageInput.text;
maleBFCresults.displayHeight = heightInput.text;
maleBFCresults.displayWeight = weightInput.text;
maleBFCresults.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:maleBFCresults animated:YES];
[maleBFCresults release];
}
几周来我一直在寻找解决此问题的方法,但没有找到任何帮助。我还没有在这个新论坛上放置所有论坛和计算,因为我想在花时间编写所有计算代码之前确保 UI 正常运行。我喜欢“modalTransitionStyle”为我提供的过渡而不是“setAnimationTransition”。这很好,因为它可以正常切换 View ,我只是无法让它将数据从 view1 传输到 view2。
我确信如果我必须这样做,我总是可以恢复到以前版本的 xcode,但我试图不必这样做,如果有人遇到类似的问题并有解决方案,我将非常感激。甚至可能有一种不同的方法可以将数据从 view1 发送到 view2,我还没有尝试过,但我也没有找到一个好的方法来做到这一点。
提前感谢您对此问题的任何帮助..
最佳答案
我也遇到了同样的移动 View 问题,并解决了如下问题。以下代码片段从 viewController 切换到 msgViewController。
打开 mainWindow.xib 并从库中添加 UIViewController 对象。将其类更改为处理指定 viewController 的类,然后单击。转到属性检查器的属性部分,为 Controller 设置相应的 Nib 名称,然后保存并退出 IB。
代码更改为
-(void) flipToBack
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
[viewController.view removeFromSuperview];
[tabBarController.view removeFromSuperview];
[self.window addSubview:[msgViewController view]];
[UIView commitAnimations];
}
希望这对你有帮助!!
如果有请沟通。
关于objective-c - 切换 View 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5129569/