[英]Drag view works in iOS7, in iOS8 it resets view to top left corner everytime
I have a view called progressView that I have made draggable like this: 我有一个名为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);
}
}
This works fine in iOS7 and I can drag it and it will stay where I left it. 这在iOS7中工作正常,我可以将其拖动到它离开的地方。 in iOS8 the view always returns to the top left corner of the view. 在iOS8中,视图始终返回到视图的左上角。 How can I fix this? 我怎样才能解决这个问题?
Thanks 谢谢
self.progressView.translatesAutoresizingMaskIntoConstraints = true; self.progressView.translatesAutoresizingMaskIntoConstraints = true;
fixes this for iOS8. 为iOS8修复了此问题。 I don't know what changed between iOS7 and iOS8 to make this an issue though, so I'd be happy to have someone explain it still. 我不知道在iOS7和iOS8之间发生了什么变化,这使它成为一个问题,因此,我很乐意让某人继续对其进行解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.