繁体   English   中英

在导航控制器上按下时,UIView页面闪烁(仅第一次)

[英]UIView page flickers (for first time only) when pushing it on navigation controller

我在UIView页面中具有以下视图层次结构:

2个UIButtons

1个ImageView

1个UILabel

1个UITableView分组样式-仅包含一个单元格(自定义单元格类型,完全使用没有任何xib的代码创建),该单元格包含以下视图层次结构:

ImageView

2 OHAttributedLabels [这是它的gitHub页面]

1个UILabel使用CGAffineTransform方法垂直旋转

我使用以下命令将这个视图的视图控制器推到导航控制器上: pushViewController方法,但是,除了第一次打开应用程序的情况之外,其他一切都正常,当第一次按下该视图控制器时,视图立即闪烁一次(带有黑色屏幕边缘上的小条),当我导航回应用程序中的其他视图,然后重新打开该视图时,不会闪烁。

这种闪烁的原因是什么?

先感谢您。

ps OHAttributedLabel在应用程序的其他视图上进行了测试,没有任何问题。

编辑:以下代码来自view1.m(在上述问题中正在谈论的视图im):

 - (void)viewDidLoad
 {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.

UIImage *backgroundImage = [UIImage imageNamed: @"bg1.png"];
UIImageView *backGroundImageView = [[[UIImageView alloc] initWithImage: backgroundImage] autorelease];
backGroundImageView.frame = CGRectMake(0,0,320,411);



[self.view addSubview: backGroundImageView];
[self.view sendSubviewToBack: backGroundImageView];

self.gsTableView.layer.cornerRadius = 10; // to make a the corner of the table view rounded

self.gsParagraphs = [NSArray arrayWithObjects:
                          NSLocalizedString(@"this is a test string this is a test string this is a test string this is a test string this is a test string this is a test string this is a test string this is a test string this is a test string" , @"test string1"), 
                      NSLocalizedString(@"this is another test string this is another test string this is another test string this is another test string this is another test string this is another test string" , @"test string2"),

                          nil];

     }

以下代码适用于view1.m文件中的cellForRowAtIndexPath方法:

      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
          {
          NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier %i", indexPath.row];
          CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (cell == nil) {
    cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];

} 

        cell.imageView.image = [UIImage imageNamed: @"gs_1.jpg"];
        cell.imageView.layer.masksToBounds = YES;
        cell.imageView.layer.cornerRadius = 5.0;
       // cell.textLabel.text = [self.gsParagraphs objectAtIndex:0]; //it will become blurry

        //note: the attributed label is used to easily apply justified alignment and many other options
        NSMutableAttributedString* cellBody1 = [NSMutableAttributedString attributedStringWithString:[self.gsParagraphs             objectAtIndex:0]];
        [cellBody1 setTextAlignment:UITextAlignmentJustify lineBreakMode: UILineBreakModeWordWrap];
        cell.secondTextLabel.attributedText = cellBody1;

        NSMutableAttributedString* cellBody2 = [NSMutableAttributedString attributedStringWithString:[self.gsParagraphs objectAtIndex:1]];
      [cellBody2 setTextAlignment:UITextAlignmentJustify lineBreakMode: UILineBreakModeWordWrap];
      cell.thirdTextLabel.attributedText = cellBody2;

       // cell.cellLabelTextYOffset = 10; this is necessary only for the original text label
        cell.cellTitle.text = NSLocalizedString(@"Test Title", @"Test Title");
        cell.cellTitleLabelWidth = 170;

       return cell;

       }

没有适用于viewDidAppear方法的代码

尚不清楚您为什么怀疑表视图控制器。 闪烁是否在表格范围内?

一些嫌疑犯:

  • 您的XIB可能会定义一个黑色背景的视图,而另一个背景则会覆盖您期望的颜色。
  • 如果视图的尺寸错误数个像素,则可能发生调整大小事件。
  • 首次实例化对象时,可能发生旋转事件。 有人告诉我,视图旋转的方向与留下黑条的方向相同。 (不确定如何发生,但它是从委托方法中记录的。)

如果为视图控制器和表委托创建了所有委托方法,则按什么顺序调用哪些委托方法?

我不知道它是否仍然有效,但是我使用了一个白色的按钮来代替一个单元格的分组表。 如果您从未计划添加另一个单元格,则几乎不需要使用整个表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM