English 中文(简体)
添加 观点之外的意见
原标题:addSubview outside the view

我有一位观点控制者,通过“[自己的观点加上:第二观点]”补充了另一种观点。 问题是,第二个观点在半部分之外增加。

secondView = [[SecondView alloc] initWithFrame: CGRectMake (-160, 0, 320, 460)];
[self.view addSubview: secondView.view]; "

然而,我已经注意到,0(-160)之前的那部分并非相互猜疑。 这是正常的吗? 是否有办法解决?

谢谢!

最佳回答

我担心,考虑到<代码>的方式。 UIResponderchain work, 您所希望的是什么是无法直接的(超级概览只能传达给其认为影响自身的事件)。

On the other hand, if you really need to have this view outside of its parent s frame, you could associate a gesture recognizer (reference) to the subview. Indeed, gesture recognizers are handled outside the normal touch event dispatching and it should work.

用于主轴:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[secondView addGestureRecognizer:singleTap];
问题回答

您可以允许通过压倒一切的<代码>点:有:接受母体外的接触。

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    BOOL pointInside = NO;

    // step through our subviews  frames that exist out of our bounds
    for (UIView *subview in self.subviews)
    {
        if(!CGRectContainsRect(self.bounds, subview.frame) && [subview pointInside:[self convertPoint:point toView:subview] withEvent:event])
        {
            pointInside = YES;
            break;
        }
    }

    // now check inside the bounds
    if(!pointInside)
    {
         pointInside = [super pointInside:point withEvent:event];
    }

    return pointInside;
}




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签