开发者

IOS: setting 'dimmer' view's alpha to greater than 0.0 disables touch events(?)

I have an app in which I am trying to allow the user to dim the display by gestures. I have a UIView which contains a number of other views and buttons, and over that I place a UIView whose background color I set to black. To have no dimming, I set the alpha of that dimmer view to zero (transparent). To effect dimming, I increase the alpha value in small steps. That appears to work well except... (you knew that was coming) whenever the alpha value becomes greater than zero, touch events are blocked -- not received as normal.

Creation of the dimmer view:

UIPanGestureRecognizer * panner = nil;
panner = [[UIPanGestureRecognizer alloc] initWith开发者_高级运维Target: self action:@selector(handlePanGesture:)];
[self.view addGestureRecognizer:panner ];
[panner setDelegate:self];
[panner release];


CGRect frame = CGRectMake(0, 0, 320, 460);
self.dimmer = [[UIView alloc] initWithFrame:frame];
[self.dimmer setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:dimmer];

handling the pan gesture:

-(IBAction) handlePanGesture:(UIPanGestureRecognizer *) sender
{
    static CGPoint lastPosition = {0};
    CGPoint nowPosition;
    float alpha = 0.0;
    float new_alpha = 0.0;
    nowPosition = [sender translationInView: [self view]];
    alpha = [dimmer alpha];

    if (nowPosition.y > lastPosition.y)
    {   NSLog(@"Down");
        new_alpha = min(alpha + 0.02,1.0);
        [dimmer setAlpha:(new_alpha)];
    }
    else if (nowPosition.y < lastPosition.y)
    { 
        NSLog(@"Up"); 
        new_alpha = max(alpha - 0.02,0);
        [dimmer setAlpha:(new_alpha)];
    }
    else
    {   NSLog(@" neither "); }
    NSLog(@"alpha = %f new_alpha = %f", alpha, new_alpha);
    lastPosition = nowPosition;
}

Any ideas why the events are getting blocked? Is there a better way to do this?

I have read several posts and googled quite a bit, but haven't seen anything very relevant.

Any and all help appreciated.

:bp:


Try setting userInteractionEnabled to NO on your dimmer view. This should tell the view not to interact with touch events, which should allow them to continue down to the views beneath the dimmer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜