Effect like deletion in ios - iphone

I need hint/code like deletion/move app effect on iOS, normally i have started the code, I am using UIButton list in UIScroll.
So my question is that supposes I have 8 to 10 button in screen and i want to change their position with dragging. for example choose 6th button and move or set to between 1 and 2. when I put them in to between the position of other button will change.
I am using UIPanGestureRecognizer for dragging.

download, Tiles-v1.0.zip, and check code, this is what i used when i needed to implement that.
reference: Move UIViews to avoid collision like rearranging icons on Springboard

If you already have the code for dragging, the rest is easy. Just use UIView Animation.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
...
[button setFrame:newFrame];
...
[UIView commitAnimations];
Basically, just move your buttons to the their new positions in that beginAnimations - commitAnimations block.
Hope this helps.

Related

sliding bar in iOS, like facebook when losing network connection

I need to provide a sliding bar in iOS to alert the user that he entered wrong data.
I want it to appear for about 1 second at the top of the screen and then disappear, so something with animcation and commit. but I couldn't find any good documentation for this.
Any ideas?
Thanks.
First you need an imageView of your notification bar or a button to be animating, which is yourObject.
With this method you put the banner on screen (change coordinates to whatever suites you) Also if you want it flip down as Apple has some of their notifications you can use the rotation, if not just delete that line.
//yourObject setHidden to NO
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.5];
self.yourObject.center = CGPointMake(100, 200);
self.yourObject.transform = CGAffineTransformMakeRotation(0);
[UIView commitAnimations];
Next just make a timer which after 1 second invokes some method to do the opposite of the one I have posted.
if you want a very simple appear and disappear instead of sliding you can replace the two lines before commitAnimations with
yourObject.alpha=1

How can I animate my views with the NSLayoutConstrains (auto layout) workaround?

I'm working to get my apps configured for the new iPhone 5. So I started with investigating the auto-layout guide of cocao touch ([link][1]) and the WDC masterclasses.
But still one thing is unclear to me. How can I animate my views.
In my previous Apps I used the regular UIView animation like:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
MyView.frame = CGRectMake(0,100, 100, 100);
[UIView commitAnimations];
Or the CGAffineTransform methods.
Can someone tell me what the best workaround is when working with auto-layout, since I'm unable to refer to frames and don't make frame-declarations anymore? Settings timers and removing and adding constraints?
The constraints are really not at all related to the animations.
However, you should use the up to date block based animation methods such as animateWithDuration:animations:.
You should use
[MyView layoutIfNeeded];
in animation block.
Yeah, when you use Auto-layout all the setFrame methods are removed. In your case if you want the View to move about certain number of pixels you can try moving the center of the view instead of setting the frame of the view and set the priority of the constraints around the view to low.

Issue with animation of UITextView in a UIView

I have a setup in which I have my main UIView, within this I display another UIView which appears to slide & expand until fully in view. Within this new view I have a UITextView, however when I run the animation to make the UIView appear it doesn't seem to apply the animation to the UITextView. The effect of this is that the UITextView just appears in its final position straight away, the rest of the UIView then slides into place. Is there a way to make the animation apply to the widgets inside the view as well?
Here is the code I'm using at the moment.
[self.view addSubview:innerView];
[innerView setFrame:CGRectMake(29.5,127,261,0)];
[textView setFrame:CGRectMake(20,20,221,0)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0];
[innerView setFrame:CGRectMake(29.5,127,261,275)];
[textView setFrame:CGRectMake(20,128,221,129)];
[UIView commitAnimations];
Please can someone help me out? I've been playing around with this problem for a long time now with no luck at all.
I had similar behavior in one of my apps. It was due to the autoresizingMask on a UITextView. Also make sure your top UIView does not have autoresizesSubviews option enable as it will influence the behavior of your UITextView on animation.

Flipping UIView inside UIScrollView

In photo app of iphone you can see smooth scrolling to the other picture with finger flicking. Is it possible to allow individual view to be 'flipped' (or rotated) to show its back side ? Found that UIScrollView is used for smooth scrolling and found the code for flipping UI. Outside of UISCrollView I got the flip to work using the code below. But once inside UIScrollView this doesn't work - it executes but UI never switches.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[UIView setAnimationDuration:1.0];
[myView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
Perhaps this is not suppose to work this way. What is the recommended way or technique to have flippable individual views inside the UIScrollView ?
Never mind. It does work. Once inside UIScrollView there were several UIViews and I needed to make sure I grab the pointer to current UIView. The above code works in this case as well. I was doing a flip on a view which was hidden :)

UITableViewCell Custom Drawing and Animating when Entering Edit/Reorder Mode

I am trying to do something very similar to this post. Starting with Atebits Fast Scrolling in Tweetie post I have a UITableView subclass that does all of it's drawing in the drawRect: method of it's contentView. This works perfectly and is super fast. What I am trying to do now is animate the transition from editing to not-editing.
An example of what I am trying to achieve would be a situation with some text right aligned in the cell. When entering edit mode, the contentView shifts right to allow room for the editing control but the text shifts offscreen on the right as well. If I simply call [contentView setNeedsDisplay] in layoutSubviews I can readjust the right aligned text but it just jumps to it's new position.
How can I get the transition to animate?
Your layoutSubviews should look like this:
-(void)layoutSubviews {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
/* Change offsets here. */
[UIView commitAnimations];
}
You may also need to add to applicationDidFinishLaunching:
[UIView setAnimationsEnabled:YES];