我有一个名为progressView的视图,我已将其设为可拖动:
-(void)viewDidLoad
...
self.panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePanGesture:)];
[self.progressView addGestureRecognizer:self.panGesture];
...
-(void) displayPollingFor:(double)numOfSeconds
{
self.progressView.hidden = NO;
self.pollTimeLeftLabel.textColor = [UIColor whiteColor];
[self.view insertSubview:self.progressView aboveSubview:self.moviePlayer.view];
self.progressView.center = CGPointMake(self.view.frame.size.width - self.progressView.frame.size.width / 2 - 10, self.moviePlayer.view.frame.size.height / 2);
self.progressView.accessibilityElementsHidden = YES;
self.progressView.translatesAutoresizingMaskIntoConstraints = false;
[UIView animateWithDuration:4 animations:^{
self.progressView.alpha = .8;
self.progressView.hidden = NO;
}];
self.progressView.thicknessRatio = 0.2;
self.progressView.textColor = [UIColor blueColor];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchPollBtn:)];
// tap.cancelsTouchesInView = NO;
[self.progressView addGestureRecognizer:tap];
self.pollEndsLabel.hidden = NO;
self.minsSecsLabel.hidden = NO;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(updateLabel:)
userInfo:nil
repeats:YES ];
pollTimeLeft = pollTimeTotal = numOfSeconds;
[self updateLabel:nil];
}
-(void)handlePanGesture:(UIGestureRecognizer*)gesture
{
self.progressView.center = [gesture locationInView:self.view];
if (self.progressView.center.y > 100) {
self.progressView.center = CGPointMake([gesture locationInView:self.view].x, 100);
}
else if (self.progressView.center.y < 30) {
self.progressView.center = CGPointMake([gesture locationInView:self.view].x, 40);
}
}
这在iOS7中运行良好,我可以拖动它,它会留在我离开的地方。在iOS8中,视图始终返回到视图的左上角。我该如何解决这个问题?
由于
答案 0 :(得分:0)
self.progressView.translatesAutoresizingMaskIntoConstraints = true;
为iOS8修复此问题。我不知道iOS7和iOS8之间的变化是什么导致这个问题,所以我很高兴有人解释它。