setNeedsDisplay不会按预期触发子视图中的drawRect [英] setNeedsDisplay does not trigger drawRect in subviews as expected

查看:116
本文介绍了setNeedsDisplay不会按预期触发子视图中的drawRect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为setNeedsDisplay苦苦挣扎.我以为应该在调用该视图的视图及其下面的层次结构(如果它在视图范围之内)时触发drawRect:的调用,但是我发现情况并非如此.这是我的设置:

I'm struggling with setNeedsDisplay. I thought it was supposed to trigger calls of drawRect: for the view for which it is called and the hierarchy below that if it's within the view's bounds, but I'm not finding that to be the case. Here is my setup:

从应用程序委托中,我创建一个视图,该视图的大小是一个正方形,基本上覆盖了整个屏幕的空间.此视图称为TrollCalendarView.除了由罗盘触发的旋转之外,TrollCalendarView几乎没有发生任何事情.

From the application delegate, I create a view whose size is a square that covers essentially the whole screen real estate. This view is called TrollCalendarView. There is not much that happens with TrollCalendarView except for a rotation triggered by the compass.

TrollCalendarView的7个子视图称为PlatformView,旨在包含围绕TrollCalendarView中心以7边排列的2D绘制对象.因此,当iPad旋转时,这7个视图会旋转,以使它们始终与基本方向对齐.

There are 7 subviews of TrollCalendarView called PlatformView intended to contain 2D draw objects arranged around the center of TrollCalendarView in a 7-sided arrangement. So when the iPad is rotated, these 7 views rotate such that they are always oriented with the cardinal directions.

每个PlatformView子视图都包含3个称为Tower的子视图.每个塔包含在drawRect:中实现的2D绘制对象.

Each of the PlatformView subviews contains 3 subviews called Tower. Each tower contains 2D draw objects implemented in drawRect:.

因此,总而言之,我有一个TrollCalendarView和一个空的drawRect:,以及分别具有drawRect实现的子视图PlatformViewPlatformview->塔.此外,Tower位于Platform的范围内,而Platform位于TrollCalendarView的范围内.

So, in summary, I have TrollCalendarView with empty drawRect:, and subviews PlatformView and Platformview -> Tower that each have drawRect implementations. Additionally, Tower lies within the bounds of Platform, and Platform lies within the bounds of TrollCalendarView.

TrollCalendarView中,我添加了滑动识别器.发生滑动时,属性会更新,并且我调用[self setNeedsDisplay],但似乎什么也没有发生.我在每个视图中的drawRect:方法中都添加了NSLog条目,并且仅调用了TrollCalendarView drawRect:方法.具有讽刺意味的是,这是一个drawRect方法为空的视图.

In TrollCalendarView I've added a swipe recognizer. When I swipe happens, a property is updated, and I call [self setNeedsDisplay] but nothing seems to happen. I added NSLog entries to drawRect: method in each of these views, and only the TrollCalendarView drawRect: method is called. Ironically, that is the one view whose drawRect method will be empty.

没有xib文件.

我该怎么做才能确保其他子视图中的drawRect方法被调用?是否有文档描述了可能影响此效果的所有细微差别?

What do I need to do to ensure the drawRect method in the other subviews is called? Is there documentation somewhere that describes all the nuances that could affect this?

推荐答案

我正在为setNeedsDisplay苦苦挣扎.我认为应该触发对其调用的视图的drawRect调用,如果它在视图范围之内,则触发其下面的层次结构

I'm struggling with setNeedsDisplay. I thought it was supposed to trigger calls of drawRect for the view for which it is called and the hierarchy below that if it's within the view's bounds

不,不是这样.你从哪里得到这个主意的?

No, that is not the case. Where did you get that idea?

-setNeedsDisplay:仅适用于将其发送到的视图.如果需要使其他视图无效,则还需要添加一些代码以将-setNeedsDisplay:发送给它们.这就是全部.

-setNeedsDisplay: applies only to the view to which it is sent. If you need to invalidate other views, you need to add some code to send -setNeedsDisplay: to them, too. That's all there is to it.

这篇关于setNeedsDisplay不会按预期触发子视图中的drawRect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆