1
我有一個UIView
,我可以拖動,一旦我停止拖動,並開始再次拖動UIView
的UIView
的座標設置回0
甚至當我拖着UIView
到特定位置。拖動的UIView設置原點座標回(0,0)
當UIView
設置可以說(x,y)
到(100,100)
?我將如何得到它的正確位置?
下面的代碼只是允許您拖動UIView
-(void)move:(id)sender {
[[[(UITapGestureRecognizer*)sender view] layer] removeAllAnimations];
CGPoint translation = [sender translationInView:self.view.superview];
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];
[self.view setFrame:CGRectMake(translation.y*4, translation.y*10, 320, 480)];
[uiWebView setFrame:CGRectMake(0, 0, 320-self.view.frame.origin.x, (320-self.view.frame.origin.x)/2)];
[uiWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"ResizeVideo('down', %0.0f, %0.0f)",320-self.view.frame.origin.x,uiWebView.frame.size.height]];
if(self.view.frame.origin.y > 0 && self.view.frame.origin.y < 400){
}
else{
CGPoint localPoint = [self.view bounds].origin;
CGPoint basePoint = [self.view convertPoint:localPoint toView:nil];
if(basePoint.y < 0){
NSLog(@"%0.0f",self.view.frame.origin.y);
[self.view setFrame:CGRectMake(0, 0, 320, 480)];
[uiWebView setFrame:CGRectMake(0, 0, 320-self.view.frame.origin.x, (320-self.view.frame.origin.x)/2)];
[uiWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"ResizeVideo('down', %0.0f, %0.0f)",320-self.view.frame.origin.x,uiWebView.frame.size.height]];
}
if(self.view.frame.origin.y > 400){
[self.view setFrame:CGRectMake(160, 400, 320, 480)];
[uiWebView setFrame:CGRectMake(0, 0, 160, 80)];
[uiWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"ResizeVideo('down', %0.0f, %0.0f)",320-self.view.frame.origin.x,uiWebView.frame.size.height]];
}
}
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
if(self.view.frame.origin.y > 200){
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.35];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
//[[sender view] setCenter:CGPointMake(200, 100)];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[self.view setFrame:CGRectMake(160, 400, 320, 480)];
[uiWebView setFrame:CGRectMake(0, 0, 160, 80)]; [UIView commitAnimations];
[uiWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"ResizeVideo('down', %0.0f, %0.0f)",160.0,80.0]];
outOfBounds1 = false;
outOfBounds2 = false;
}
if(self.view.frame.origin.y < 200){
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.35];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
//[[sender view] setCenter:CGPointMake(160, 72)];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[self.view setFrame:(CGRectMake(0, 0, 320, 480))];
[uiWebView setFrame:CGRectMake(0, 0, 320, 144)]; [UIView commitAnimations];
[uiWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"ResizeVideo('down', %0.0f, %0.0f)",320.0,144.0]];
outOfBounds1 = false;
outOfBounds2 = false;
}
}
NSLog(outOfBounds1 ? @"Yes" : @"No");
}
:謝謝。現在完成它的工作。 – redoc01
沒問題:)你也可以upvote我的答案? – RaffAl