문제

EDIT: Is there any way to programatically touchdown on a UIView?

When the user touches down the UIButton, the appdelegate sets a new rootviewcontroller. The new controller has a screenshot of the last view, and I would like the user to swipe the "view" (image) off the screen. Everything is working perfectly, but I can't seem to engage the UIPanGestureRecognizer until the finger is lifted and then touched down again. So for I've tried to programatically add a UIControlEvent -- in hindsight, that kind of makes no sense.

Anyways, got any ideas?

도움이 되었습니까?

해결책

Well, you certainly can get a touch down followed by a pan to work on a button if you add a pan gesture recognizer to the button, and have the button's action set to fire on touch down. I think the proper way to make the transition would be to have the button's touch down method instantiate the new controller, and add its view to the window's subviews. Then, the swipe (or pan) would animate out the old view, switch the root view controller, and finally, remove the old view from the window. With this method, you don't need to use a screenshot, or mess around with trying to pass on that original touch to a new view. Something like this (I used a swipe rather than a pan for simplicity):

- (IBAction)touchDownMethod:(UIButton *)sender {

    self.nextVC = [self.storyboard instantiateViewControllerWithIdentifier:@"NextVC"];
    self.nextVC.view.frame = self.view.frame;
    [self.view.window insertSubview:self.nextVC.view belowSubview:self.view];

}


- (IBAction)SwipeAwayInitialController:(UISwipeGestureRecognizer *)sender {

    [UIView animateWithDuration:.5 animations:^{
        self.view.center = CGPointMake(self.view.center.x - self.view.bounds.size.width, self.view.center.y);
    } completion:^(BOOL finished) {
        self.view.window.rootViewController = self.nextVC;
        [self.view removeFromSuperview];
    }];
}

다른 팁

Set a new rootviewcontroller on touch up instead of touch down and that will solve your problem.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top