iPhone - 简单的方式来按 - >删除效果?或移动 - >重新定位视图效果?

Jac*_*ack 3 iphone uiview shake

在iphone的家中,您可以按住一个应用程序2秒钟,然后每个人都在颤抖,等待删除或重新定位.

我怎么能在自己的视野中拥有这个?

  1. 按住某个地方,每个子视图都在颤抖

  2. 按住某处以便用户可以重新定位视图?

就像iOs的主屏幕或ibook或其他很多应用程序一样?

谢谢

Vin*_*Vin 6

1)您必须使用UILongPressGestureRecognizer来检测长按

    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(startWobbling)];
[anyView addGestureRecognizer:longPressGesture];
[longPressGesture release];
Run Code Online (Sandbox Code Playgroud)

然后在startWobbling选择器中执行:

CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-5.0));
CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(5.0));


view.transform = leftWobble;  // starting point

[UIView beginAnimations:@"wobble" context:view];
[UIView setAnimationRepeatAutoreverses:YES]; // important
[UIView setAnimationRepeatCount:10];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(wobbleEnded:finished:context:)];

btn.transform = rightWobble; // end here & auto-reverse

[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)

2)请参阅Apple的示例代码:http://developer.apple.com/library/ios/#samplecode/Touches/Introduction/Intro.html