问题标签 [setneedsdisplay]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
android - 如何在android中打开和关闭显示?
我想使用接近传感器禁用输入(或关闭显示)。
屏幕输入必须通过接近传感器更改来禁用和启用(关闭和打开)。
我在这里搜索了很多问题,但没有找到任何合适的答案。在我尝试过的代码中显示关闭。但是当接近度改变时,显示器没有打开。
这是 onSensorChanged 方法:
cocoa - NSTextView setNeedsDisplay not working under Mavericks?
My MacOS Cocoa application displays a window of static text, meaning it should not be changed by the user, should not be first responder, etcetera. The only thing that happens to the text is that each word of it changes color (from "idleColor" to "highlightColor", and then back again) at a specific point in time. It is similar to a Karaoke display - individual words change color, and then change back, under program control, based on a list of timed events.
All of this works beautifully under MacOS 10.7 and 10.8. BUT, under 10.9, the text color does NOT change UNLESS I click in the window and continually move the cursor around, so I am manually highlighting (and un-highlighting) some of the text, continuously. If I do this, the regular words behave as intended. Essentially, it feels like the OS is refusing to update the window under program control, unless I am forcing it to update by manually performing something that requires the UI to respond.
The code that performs the color changes is as follows:
(sTextView is a subclass of NSTextView.)
Now, if I comment out that last line, then I get the same, incorrect behavior under 10.7 and 10.8. In other words, under 10.9, the setNeedsDisplay method is not working, or not working the same way.
Does anyone have any ideas about working around this, or have any other light to shed on the problem? Or am I doing something terribly wrong? It is CRITICAL to the application that the changes to the textColor happen without latency!
EDITING MY QUESTION - to answer it:
Found the answer elsewhere here! I needed to call setNeedsDisplay on the main thread - it was in a secondary thread. The weird thing is that it always seemed to work fine under 10.7 and 10.8. It only broke under 10.9. So I just changed this:
To this:
…and it seem to have worked. Hope this helps someone else…</p>
ios - iOS:[self.view setNeedsDisplay];
我似乎忘记了这方面的基础知识,或者我只是太累了。
我有一个视图控制器和一个UIView
名为 MyViewClass 的子类视图。
在viewDidLoad
我的 viewController 中,我alloc
喜欢init
self.myView
这样:
有时在我的 viewController 中,我会调用[self.view setNeedsDisplay];
. 这里没问题。
我在 MyViewClass.h 中公开了一个属性:
该属性i
将drawRect
在 myView 中使用;所以,从我的 viewController 我会这样设置:
所以我的问题是:
为什么我可以[self.view setNeedsDisplay];
在不需要调用的情况下调用我的视图控制器[self.myView setNeedsDisplay];
并将drawRect
在 myView 中调用,但我不能像self.view.i
在我的视图控制器中self.myView
已经分配的self.view
那样viewDidLoad
在我的视图控制器中进行操作?
objective-c - 如何用一条线连接两个 UIView?
我有一个名为 UIView 的子类MENode
。每个MENode
都有一个 NSMutableDictionary 来跟踪它的子节点(也是MENode
s)。我想要实现的是从父节点到子节点画一条线。这是我的drawRect:
in实现MENode
:
下面的两个方法都由视图控制器调用。我[self setNeedsDisplay];
两个都叫:
当我运行它时,我没有得到任何线条,只有节点。在此先感谢您的帮助。
cocoa - isOpaque 不会停止传递给父母 drawRect
我遇到了 Cocoa 及其视图重绘层次结构的问题。
我目前正在测试仪表样式控件中的显示(音频)级别,并且我正在使用来自苹果的 MatrixMixerTest 示例项目的 MeteringView 类。这个类正在绘制仪表,只绘制变化的差异,这看起来是一个非常有效的类。
我的项目分为 2 个拆分视图,其中一些是 NSCollectionViews(滚动视图、剪辑视图),而另一些只是静态视图。如果我将仪表添加到那些“静态”视图中,当这些视图调用 setNeedsDisplay:YES 时它们可以正常工作。如果将仪表添加到 CollectionView 项目的视图中,它会被渲染,但会丢失其绘制的“旧级别”部分及其角/背景。我认为发生这种情况是因为 CollectionView 项目也被称为重绘(具有背景图像)并且一切都消失了。它正在绘制一些当前正在变化的部分(绘图作品)。
有没有办法防止 Item 本身被重绘?或者,我不知道为什么在那些静态视图中没有发生这种情况,因为这些视图也有背景图像,但不会在仪表上绘制。
CollectionView 中是否有一些技巧或与“正常”视图中的不同之处?
编辑:阅读有关 isOpaque (MeteringView isOpaque = YES) 后意味着如果设置为 yes,则不应调用父视图 drawRect。好吧,这适用于静态视图,那些 MeteringViews 不调用父母 drawRect,但是 CollectionView 中的那些。我不知道为什么。
编辑 2:我给这个主题另一个标题,因为 MeteringView 中的 isOpaque=YES 并没有停止在 CollectionView 中调用父母 drawRect,在正常视图中它正在工作。有什么需要了解的吗?我必须停止重绘 CollectionView 项目,因为这就是问题所在。
提前谢谢各位
本杰明
ios - 设置 contentInset 或 automaticAdjustsScrollViewInsets 后我需要做什么才能实际应用它?
我有一个UIViewController
包含一个UIScrollView
. 最初automaticallyAdjustsScrollViewInsets
没有设置(所以它应该默认为YES
)。
在某些用户交互上我设置automaticallyAdjustsScrollViewInsets
为,所以我可以在滚动视图上NO
设置我自己的。contentInset
这样做之后什么也没有发生。之后我要打什么电话?
调用setNeedsDisplay
滚动视图没有帮助。
ios - 你能从一个班级发送消息来触发另一个班级的“自我”吗?
我正在从我一直在学习的一本书课程中改编一个程序,它有三个类:一个视图控制器、一个视图和一个包含其他两个共享变量的单例。
我正在尝试在视图控制器中编写一些代码,这些代码随后将触发视图发送 [self setNeedsDisplay] 消息。但是,当我将其设置为实例方法时,编译器会抛出“无类方法”异常。当我将方法更改为类方法时,“self”属性不再起作用。
老实说,总的来说,我仍然对 OOP 的许多区别有所了解,因此我可能无法完全掌握情况。但我想知道,是否可以从一个班级向另一个班级发送一条消息,触发第二个班级发起“自我”行动?
这是视图控制器中将发送消息的代码(使用我当前的编码尝试):
这是视图类中将接收消息的代码:
不确定它有多相关,但这是我的单例类:
如果有人对此有任何想法和/或意见,我很想听听他们的意见!
ios - 没有从 setNeedsDisplay 调用 drawRect
我最近开始学习核心图形以在视图上绘制,但每次调用时setNeedsDisplay
,该方法都会运行但不会触发drawRect
。在我的项目中,我在视图控制器上有一个视图。该视图包含一个 if 语句,drawRect
用于检查 BOOL 变量是 YES 还是 NO。如果是,它使用代码绘制一个红色圆圈。如果否,则绘制一个蓝色圆圈。在 BOOL 的设置器中,它调用setNeedsDisplay
. 我在 ViewController 中创建了这个视图类的一个实例并设置了 BOOL 但视图没有重绘。为什么没有调用该方法?我在下面发布了 xcode 文件和代码位。
自定义视图.m:
自定义视图.h:
视图控制器.m:
完整项目:https ://www.mediafire.com/?2c8e5uay00wci0c
谢谢
ios - setNeedsDisplay 不会改变 UITableView 的中心
UITableView
通过IB添加了一个。我正在尝试以UITableView
编程方式更改中心:
日志:
正如您在日志中看到的那样,Y 轴值发生了UITableView
变化,但我没有看到任何视觉效果或在我调用setNeedsDisplayUITableView
时被重绘,我也不明白为什么Y 轴值会恢复为788 每次我通过单击调用此代码时。UIButton
ios - setNeedsDisplay 在后台线程上不起作用
我setNeedsDisplay
在一个新线程中调用该方法,但在我的视图中没有看到任何变化。setNeedsDisplay
调用新线程后,我应该怎么做才能看到我的所有更改?