我怎么知道,如果一个视图可见或不? [英] How do I know if a view is visible or not?

查看:154
本文介绍了我怎么知道,如果一个视图可见或不?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有两个视图控制器:XVC和YVC。我已经使用了震动API和并用的方法 - (无效)motionBegan - (无效)motionEnded: - (无效)motionCancelled 在XVC。会发生什么事是当设备被动摇,它激发一个简单的动画。现在的事情是,这个动画被触发甚至当我打开YVC即当 yVS.view 已添加为子视图。我所寻找的是,如果一些条件,我可以在使用 - (无效)motionEnded:是这样的:

Say I have two view controllers: xVC and yVC. I have used the shake API and and have used the methods -(void)motionBegan,-(void)motionEnded: and -(void)motionCancelled in xVC. What happens is when the device is shaken, it fires a simple animation. Now the thing is that this animation is fired even when the I have yVC open that is, when yVS.view has been added as the subview. What I am looking for is some if condition which I can use in -(void)motionEnded: like this:

if(yVC == nil)
{
     //trigger animation
} 

我的意思是,当YVC可见摇不应该工作。我怎么做?请帮助。

By that I mean that the shake shouldn't work when yVC is visible. How do I do that? Please help.

推荐答案

我所看到的和所使用的一般建议是请一个观点,如果它有一个非空窗口属性:

The general advice I have seen and used is to ask a view if it has a non-nil window property:

if( ! yVC.view.window) {
  // trigger animation
}

但请注意,这并不总是的使用是可见的等同;尽管在大多数应用程序是一样好,你可以得到performantly(如果它是不准确的基本情况是有不同的看法完全遮住了,但是这可能仍然满足您的需求)

But note that this doesn't always equate with being visible; though in most apps it's about as good as you can performantly get (the basic case where it's not accurate is when a different view completely obscures it, but this may still satisfy your needs)

这篇关于我怎么知道,如果一个视图可见或不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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