【发布时间】:2011-03-04 15:24:27
【问题描述】:
如何确保滚动条中的图像能够从滚动条拖到图像视图中?
我也想实现一个“摆动”。当用户点击滚动条中的图像时,图像会摆动并跟随用户触摸到另一个视图。我开始制作一个子视图,但是当图像在普通视图上显示时,它的位置会更改为位于视图顶部而不是底部。
我怎样才能确保当我触摸图像时:
- 图像摆动
- 图像转到另一个视图。
- 图像跟随我的触摸位置
(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
image1.userInteractionEnabled = YES;
[self.view addSubview:image1];
if([touch view] == image1){
image1.center = location;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.14];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:1000000];
image1.transform = CGAffineTransformMakeRotation(69);
image1.transform = CGAffineTransformMakeRotation(-69);
[UIView commitAnimations];
image1.center = CGPointMake(30,870);
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *) event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if([touch view] == image1){
image1.userInteractionEnabled = YES;
[self.view addSubview:image1];
image1.center = location;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.14];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:1000000];
image1.transform = CGAffineTransformMakeRotation(69);
image1.transform = CGAffineTransformMakeRotation(-69);
[UIView commitAnimations];
}
【问题讨论】:
标签: image uiscrollview drag