我的编程方式创建了一个登录图和表格来看。

在某些情况下它我不能重现有发生一些奇怪的视觉的错误:

  • 案文与一些字母具有不同的字体大小比其他人
  • 按钮在那里的边界不是最初所示,但只有当你点击它。在相同的情况下,边界按钮可以显示在一个UITextField而不是地方支架(见的截图)
  • 标显示不是在正确的地方,但是在上面提到的文本框颠倒了(我没有管理的截图中这个尚未)

下面,我加入两个截与大多数应用程序的昏了过去,只表示的错误:

http://uppix.net/b/c/4/dd1e41acb94b7d0ad8eb173772e97.png   http://uppix.net/b/f/2/a5993440c07753b851701068330be.png

在这里你可以看到的文本变得混合不同的字体大小。

这一错误发生的不定期或重现。

我加入代码登录屏幕下:

 // Implement loadView to create a view hierarchy programmatically, without 
 // using a nib.
     - (void)loadView {
     UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
     UIFont* font = [UIFont systemFontOfSize:14];

 float midLine = 100.0;
 float height = 30.0;
 float borderY = 70.0;
 float borderX = 10.0;
 float width = 320.0 - borderX * 2.0;
 float paddingX = 10.0;
 float paddingY = 5.0;

 CGRect usernameLabelRect = CGRectMake(borderX, borderY, midLine, height);
 CGRect usernameFieldRect = CGRectMake(borderX + midLine + paddingX, borderY, 
                               width - midLine - paddingX - 40 , height);

 CGRect passwordLabelRect = CGRectMake(borderX, borderY + height + paddingY,
                               midLine, height);
 CGRect passwordFieldRect = CGRectMake(borderX + midLine + paddingX, 
                               borderY + height + paddingY, 
                               width - midLine - paddingX - 40, height);

 CGRect loginButtonRect = CGRectMake(borderX + 40, 
                               borderY + height*2 + paddingY*2, width - 80, 
                               height);

 //CGRect warningRect =  CGRectMake(borderX,
 //                         borderY * height * 3.0 + paddingY *3.0, 
 //                         width, height);
 CGRect warningRect =  CGRectMake(borderX, 175, width, 40);

 UILabel* usernameLabel = [[UILabel alloc] initWithFrame:usernameLabelRect];

 usernameLabel.textAlignment = UITextAlignmentRight;
 usernameLabel.font = font;
 usernameLabel.text = @"Username:";

 UILabel* passwordLabel = [[UILabel alloc] initWithFrame:passwordLabelRect];
 passwordLabel.textAlignment = UITextAlignmentRight;
 passwordLabel.font = font;
 passwordLabel.text = @"Password:";


 usernameField = [[UITextField alloc] initWithFrame:usernameFieldRect];
 [usernameField setBorderStyle:UITextBorderStyleRoundedRect];
 //[usernameField setPlaceholder:@"<Username>"];
 usernameField.font = font;
 usernameField.autocapitalizationType = UITextAutocapitalizationTypeNone;
 usernameField.autocorrectionType = UITextAutocorrectionTypeNo;

 passwordField = [[UITextField alloc] initWithFrame:passwordFieldRect];
 passwordField.font = font;
 [passwordField setBorderStyle:UITextBorderStyleRoundedRect];
 //[passwordField setPlaceholder:@"<Password>"];
 passwordField.autocapitalizationType = UITextAutocapitalizationTypeNone;
 passwordField.autocorrectionType = UITextAutocorrectionTypeNo;
 passwordField.secureTextEntry = YES;

 loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 loginButton.frame = loginButtonRect;
 [loginButton setTitle: @"Einloggen" forState:UIControlStateNormal];
 [loginButton setTitleColor:[UIColor blackColor]
                                    forState:UIControlEventTouchDown];
 loginButton.contentVerticalAlignment =
                                    UIControlContentVerticalAlignmentCenter;
 loginButton.contentHorizontalAlignment =
                                    UIControlContentHorizontalAlignmentCenter;
 [loginButton addTarget:self action:@selector(OnLoginClicked:)
                          forControlEvents:UIControlEventTouchUpInside];
 [loginButton setBackgroundColor:[UIColor clearColor]];

 warningLabel = [[UILabel alloc] initWithFrame:warningRect];
 warningLabel.font = font;
 warningLabel.numberOfLines = 3;
 warningLabel.text =
 @"Wenn Sie die Applikation jetzt schließen, so werden Ihre Logindaten verworfen.";

 [myView addSubview:usernameLabel];
 [myView addSubview:passwordLabel];
 [myView addSubview:usernameField];
 [myView addSubview:passwordField];
 [myView addSubview:loginButton];
 [myView addSubview:warningLabel];
 /*
 [usernameLabel release];
 [passwordLabel release];
 [usernameField release];
 [passwordField release];
 [loginButton release];
 [warningLabel release];
 */
 self.view = myView;
 [myView release];
}
有帮助吗?

解决方案 2

问题是我称为UIKit的消息不是非主要程,这导致各种图形问题。解决它通过使用performSelectorOnMainThread:在几个地方,在我的代码=)

其他提示

我不能工作的所有屏幕上的定位在我的头,但是它看起来我喜欢你的许多领域的重叠:这是故意的?也许这就是原因?我通常创建景码,但这可能是一种情况下IB!

你还没有显示任何代表看来,然而我们似乎类似的问题之前,在其中添加有关子视图处于一个细胞,然后接下来的时间该单元被取消排队与DequeueReusableCell添加有关子视图处再次不经检查,如果他们在那里或清除它们。这种结果在各种各样的重叠,就像第一截图。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top