简体   繁体   English

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

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

I have the following view hierarchy in a UIView page: 我在UIView页面中具有以下视图层次结构:

2 UIButtons 2个UIButtons

1 ImageView 1个ImageView

1 UILabel 1个UILabel

1 UITableView - grouped style - contains only one cell (of type custom cell, created completely with code without any xib), the cell contains this view hierarchy: 1个UITableView分组样式-仅包含一个单元格(自定义单元格类型,完全使用没有任何xib的代码创建),该单元格包含以下视图层次结构:

ImageView

2 OHAttributedLabels [here's its gitHub page] 2 OHAttributedLabels [这是它的gitHub页面]

1 UILabel rotated vertically using CGAffineTransform method 1个UILabel使用CGAffineTransform方法垂直旋转

I push the view controller of this view on a navigation controller using: pushViewController method, however, everything works fine except for the case of opening the application for the first time, when this view controller is pushed the view instantly flickers once (with some black strips on screen edges), when I navigate back to other views in the application, and then reopen this view, no flickering happens. 我使用以下命令将这个视图的视图控制器推到导航控制器上: pushViewController方法,但是,除了第一次打开应用程序的情况之外,其他一切都正常,当第一次按下该视图控制器时,视图立即闪烁一次(带有黑色屏幕边缘上的小条),当我导航回应用程序中的其他视图,然后重新打开该视图时,不会闪烁。

what is the cause of this flickering ? 这种闪烁的原因是什么?

thank you in advance. 先感谢您。

ps the OHAttributedLabel is tested on other views in the application without any problems. ps OHAttributedLabel在应用程序的其他视图上进行了测试,没有任何问题。

EDIT: the following code is from view1.m (the view im talking about in the question above): 编辑:以下代码来自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];

     }

and the following code is for cellForRowAtIndexPath method in view1.m file: 以下代码适用于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;

       }

there is no code for viewDidAppear method 没有适用于viewDidAppear方法的代码

Its a little unclear why you suspect your table view controller. 尚不清楚您为什么怀疑表视图控制器。 Is the flicker inside table's bounds? 闪烁是否在表格范围内?

Some suspects: 一些嫌疑犯:

  • Your XIB may define one view with a black background that is covered by another view with your expected color. 您的XIB可能会定义一个黑色背景的视图,而另一个背景则会覆盖您期望的颜色。
  • a resize event can happen if the view is the wrong size by a few pixels. 如果视图的尺寸错误数个像素,则可能发生调整大小事件。
  • a rotate event could happen when the objects are first instantiated. 首次实例化对象时,可能发生旋转事件。 I have been told of a case where the view was getting a rotate from and to the same orientation which left black bars. 有人告诉我,视图旋转的方向与留下黑条的方向相同。 (Not sure how that happened, but it was logged from within the delegate methods.) (不确定如何发生,但它是从委托方法中记录的。)

If you create all the delegate methods for both the view controller and table delegates, which ones are called in what order? 如果为视图控制器和表委托创建了所有委托方法,则按什么顺序调用哪些委托方法?

I don't know if it still works, but I have used a single white button in place of a one-cell grouped table. 我不知道它是否仍然有效,但是我使用了一个白色的按钮来代替一个单元格的分组表。 If you never plan to add another cell, there is little need to use an entire table. 如果您从未计划添加另一个单元格,则几乎不需要使用整个表。

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

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