开发者

iphone - easy way to have that press -> delete effects? or move -> relocate view effect?

开发者 https://www.devze.com 2023-01-29 01:17 出处:网络
On iphone\'s home, you can press and hold on one app for 2 secs, then everyone is shaking and waiting to be delete or relocate.

On iphone's home, you can press and hold on one app for 2 secs, then everyone is shaking and waiting to be delete or relocate.

How can I have this in my own view?

  1. press & hold on somewhere and every subview is shaking

  2. press & hold on somewhere 开发者_StackOverflowso user can relocate the views?

Just like iOs's home screen or ibook or quite many other apps?

thanks


1) You'd have to use UILongPressGestureRecognizer to detect long presses

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

and then in the startWobbling selector do:

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];

2) Refer Touches sample code from Apple: http://developer.apple.com/library/ios/#samplecode/Touches/Introduction/Intro.html


You can use the TTLauncher view from the Three20 lib. It is pretty easy to customize and gives you all the wobbling and relocating you are looking for: http://three20.info/showcase/launcher

0

精彩评论

暂无评论...
验证码 换一张
取 消