iOS: swipe gesture to load different data within same controller - ios

In my application I'm trying to implement a functionality (similar to calendar where month changes within same view) something like if current view shows the news of current day (today) then if user swipe right, it should show the next day news and on swipe left it should show previous day news.
I have so far
a single NewsViewController which shows the today news in table view
On other topics many suggest to use libraries like on this question Tom suggests Handling a view controller that slides in with either way swipe
I am new to IOS development and have no idea how to do it, any help will be greatly appreciated.

So you can try pulling data in any of the gesture methods using this cod here https://stackoverflow.com/a/20596933/1307844
Your answer is totally how you implement your gesture methods.

I found the solution and here is my code snippets...
ViewDidLoad:
UISwipeGestureRecognizer *oneFingerSwipeLeft = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:#selector(oneFingerSwipeLeft:)];
[oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[viewContent addGestureRecognizer:oneFingerSwipeLeft];
UISwipeGestureRecognizer *oneFingerSwipeRight = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:#selector(oneFingerSwipeRight:)];
[oneFingerSwipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[viewContent addGestureRecognizer:oneFingerSwipeRight];
oneFingerSwipeLeft:
- (void)oneFingerSwipeLeft:(UITapGestureRecognizer *)recognizer {
newsList = [[NSMutableArray alloc] init];
//to animate the view as new view is loaded
[UIView animateWithDuration:0.1 animations:^{
viewContent.frame = CGRectMake( -viewContent.frame.size.width, viewContent.frame.origin.y , viewContent.frame.size.width, viewContent.frame.size.height);
[self loadData];
} completion:^(BOOL finished) {
viewContent.frame = CGRectMake( viewContent.frame.size.width,viewContent.frame.origin.y, viewContent.frame.size.width, viewContent.frame.size.height);
[UIView animateWithDuration:0.3 animations:^{
viewContent.frame = CGRectMake(0.0, viewContent.frame.origin.y, viewContent.frame.size.width, viewContent.frame.size.height);
}];
}];
selectedDay++;
[self fetchDataFromWeb];
}
oneFingerSwipeRight:
- (void)oneFingerSwipeRight:(UITapGestureRecognizer *)recognizer {
newsList = [[NSMutableArray alloc] init];
//to animate the view as new view is loaded
[UIView animateWithDuration:0.1 animations:^{
viewContent.frame = CGRectMake( viewContent.frame.size.width, viewContent.frame.origin.y , viewContent.frame.size.width, viewContent.frame.size.height);
[self loadData];
} completion:^(BOOL finished) {
viewContent.frame = CGRectMake( -viewContent.frame.size.width,viewContent.frame.origin.y, viewContent.frame.size.width, viewContent.frame.size.height);
[UIView animateWithDuration:0.3 animations:^{
viewContent.frame = CGRectMake(0.0, viewContent.frame.origin.y, viewContent.frame.size.width, viewContent.frame.size.height);
}];
}];
selectedDay--;
[self fetchDataFromWeb];
}
Thanks to #BalramTiwari for valuable suggestion.

Here is IceFish's answer in swift:
override func viewDidLoad() {
super.viewDidLoad()
let swipeRight = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.view.addGestureRecognizer(swipeRight)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeLeft.direction = UISwipeGestureRecognizerDirection.Left
self.view.addGestureRecognizer(swipeLeft)
and the responder:
func respondToSwipeGesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.Left:
UIView.animateWithDuration(0.1, animations: {
let myFrame = self.view.frame
self.view.frame = CGRectMake(-myFrame.size.width, myFrame.origin.y , myFrame.size.width, myFrame.size.height)
}, completion: {_ in
let myFrame = self.view.frame
self.view.frame = CGRectMake(myFrame.size.width, myFrame.origin.y , myFrame.size.width, myFrame.size.height)
UIView.animateWithDuration(0.3, animations: {
let myFrame = self.view.frame
self.view.frame = CGRectMake(0.0, myFrame.origin.y , myFrame.size.width, myFrame.size.height)
}, completion: nil)
})
// do left action here
case UISwipeGestureRecognizerDirection.Right:
UIView.animateWithDuration(0.1, animations: {
let myFrame = self.view.frame
self.view.frame = CGRectMake(myFrame.size.width, myFrame.origin.y , myFrame.size.width, myFrame.size.height)
}, completion: {_ in
let myFrame = self.view.frame
self.view.frame = CGRectMake(-myFrame.size.width, myFrame.origin.y , myFrame.size.width, myFrame.size.height)
UIView.animateWithDuration(0.3, animations: {
let myFrame = self.view.frame
self.view.frame = CGRectMake(0.0, myFrame.origin.y , myFrame.size.width, myFrame.size.height)
}, completion: nil)
})
// do right action here
default:
break
}
}
}

Related

UIPanGesture not moving individual view

I am doing a iPhone project in Swift where on top of my homeScreen, I am adding multiple views in a stack.
My requirement is to be able to move each individual child view on top of the homeScreen like Tinder card swiping effect. I am using UIPanGesture to achieve this so that the each individual view follows my finger on screen.
But my problem is that instead of the desired effect of moving only one screen all the stack of Views is moving together on my Home Screen.
I am stuck at this problem for the last 4 days. Kindly help me out.
Xcode Version 7.2.1 and Swift 2.1
Here is the code that moves the UIView:
//For creating each childView and adding UIPanGestureRecognizer to each childView
func configureInitialViewPlacement() -> Void {
for var i:Int = cardsArray.count-1; 0 <= i; i--
{
let cardView = cardsArray[i]
let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "beingDragged:")
cardView.addGestureRecognizer(panGestureRecognizer)
self.view.addSubview(cardView)
var frame = CGRectZero
var originalFrame = self.view.bounds
originalFrame = CGRectMake(originalFrame.origin.x+10,originalFrame.origin.y+10 , originalFrame.size.width-20, originalFrame.size.height-20)
frame.size.height = originalFrame.size.height
frame.size.width = originalFrame.size.width - CGFloat((2*CGFloat(i)*paddingOffset))
frame.origin.x = originalFrame.origin.x + CGFloat((CGFloat(i)*paddingOffset))
frame.origin.y = originalFrame.origin.y + CGFloat((CGFloat(i)*paddingOffset))
cardView.frame = frame
cardView.setContentViewForCard(cardDataArray[i])
}
}
// Method For gestureRecognizer
func beingDragged(gestureRecognizer: UIPanGestureRecognizer) -> Void {
xFromCenter = Float(gestureRecognizer.translationInView(self.view).x)
yFromCenter = Float(gestureRecognizer.translationInView(self.view).y)
switch gestureRecognizer.state {
case UIGestureRecognizerState.Began:
self.originPoint = self.view.center
case UIGestureRecognizerState.Changed:
let rotationStrength: Float = min(xFromCenter/ROTATION_STRENGTH, ROTATION_MAX)
let rotationAngle = ROTATION_ANGLE * rotationStrength
let scale = max(1 - fabsf(rotationStrength) / SCALE_STRENGTH, SCALE_MAX)
self.view.center = CGPointMake(self.originPoint.x + CGFloat(xFromCenter), self.originPoint.y + CGFloat(yFromCenter))
let transform = CGAffineTransformMakeRotation(CGFloat(rotationAngle))
let scaleTransform = CGAffineTransformScale(transform, CGFloat(scale), CGFloat(scale))
self.view.transform = scaleTransform
self.updateOverlay(CGFloat(xFromCenter))
case UIGestureRecognizerState.Ended:
self.afterSwipeAction()
case UIGestureRecognizerState.Possible:
fallthrough
case UIGestureRecognizerState.Cancelled:
fallthrough
case UIGestureRecognizerState.Failed:
fallthrough
default:
break
}
}
func afterSwipeAction() -> Void {
let floatXFromCenter = Float(xFromCenter)
if floatXFromCenter > ACTION_MARGIN {
self.rightAction()
} else if floatXFromCenter < -ACTION_MARGIN {
self.leftAction()
} else {
UIView.animateWithDuration(0.3, animations: {() -> Void in
self.view.center = self.originPoint
self.view.transform = CGAffineTransformMakeRotation(0)
})
}
}
// For Right Swipe
func rightAction() -> Void {
let finishPoint: CGPoint = CGPointMake(500, 2 * CGFloat(yFromCenter) + self.originPoint.y)
UIView.animateWithDuration(0.3,
animations: {
self.view.center = finishPoint
}, completion: {
(value: Bool) in
self.cardsArray[0].removeFromSuperview()
})
delegateforcard.cardSwipedRight(self.cardsArray[0])
}
// For Left Swipe
func leftAction() -> Void {
let finishPoint: CGPoint = CGPointMake(-500, 2 * CGFloat(yFromCenter) + self.originPoint.y)
UIView.animateWithDuration(0.3,
animations: {
self.view.center = finishPoint
}, completion: {
(value: Bool) in
self.cardsArray[0].removeFromSuperview()
})
delegateforcard.cardSwipedLeft(self.cardsArray[0])
}
Let me know if you need more clarifications.
Thanks.
I have also done the same in objective-c, You can get an idea from here,
Here is my code
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:#selector(cardMoving:)];
-(void)cardMoving:(UIPanGestureRecognizer *)gestureRecognizer
{
xValueFromCenter = [gestureRecognizer translationInView:self].x; // if right positive(+) value, negative for left
yValueFromCenter = [gestureRecognizer translationInView:self].y; // if swipe up positive(+), negative for down
switch (gestureRecognizer.state) {
case UIGestureRecognizerStateBegan:{
originalPoint = self.center;
break;
};
case UIGestureRecognizerStateChanged:{
CGFloat rotationStrength = MIN(xValueFromCenter / ROTATION_STRENGTH, ROTATION_MAX);
CGFloat rotationAngel = (CGFloat) (ROTATION_ANGLE * rotationStrength);
CGFloat scale = MAX(1 - fabs(rotationStrength) / SCALE_STRENGTH, SCALE_MAX);
self.center = CGPointMake(originalPoint.x + xValueFromCenter, originalPoint.y + yValueFromCenter);
CGAffineTransform transform = CGAffineTransformMakeRotation(rotationAngel);
CGAffineTransform scaleTransform = CGAffineTransformScale(transform, scale, scale);
self.transform = scaleTransform;
[self updateOverlay:xValueFromCenter];
break;
};
case UIGestureRecognizerStateEnded: {
[self afterSwipeAction];
break;
};
case UIGestureRecognizerStatePossible:break;
case UIGestureRecognizerStateCancelled:break;
case UIGestureRecognizerStateFailed:break;
}
}
-(void)updateOverlay:(CGFloat)distance
{
if (distance > 0) {
overlayView.Direction = GGOverlayViewDirectionRight;
} else {
overlayView.Direction = GGOverlayViewDirectionLeft;
}
overlayView.alpha = MIN(fabs(distance)/100, 0.7);
}
- (void)afterSwipeAction
{
if (xValueFromCenter > ACTION_MARGIN) {
[self rightAction];
} else if (xValueFromCenter < -ACTION_MARGIN) {
[self leftAction];
} else { //for reseting the card
[UIView animateWithDuration:0.3
animations:^{
self.center = originalPoint;
self.transform = CGAffineTransformMakeRotation(0);
overlayView.alpha = 0;
}];
}
}

How to make the tabbar custom animation only occur for a certain view controller?

I have a custom animation for when the tabs are selected, but instead I want that animation to only occur for when a certain tab is clicked. I am guessing it has to do with the instantiation of the toView. Error http://puu.sh/n5VuA/c3e886957e.png
class TransitioningObject: NSObject, UIViewControllerAnimatedTransitioning {
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
// Get the "from"nd "to" views
let fromView : UIView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
let toView : UIView = transitionContext.viewForKey(UITransitionContextToViewKey)!
transitionContext.containerView()!.addSubview(fromView)
transitionContext.containerView()!.addSubview(toView)
//The "to" view with start "off screen" and slide left pushing the "from" view "off screen"
toView.frame = CGRectMake(toView.frame.width, 0, toView.frame.width, toView.frame.height)
let fromNewFrame = CGRectMake(-1 * fromView.frame.width, 0, fromView.frame.width, fromView.frame.height)
UIView.animateWithDuration(transitionDuration(transitionContext), animations: { () -> Void in
toView.frame = CGRectMake(0, 0, 320, 560)
fromView.frame = fromNewFrame
}) { (Bool) -> Void in
transitionContext.completeTransition(true)
}
}
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return 0.35
}
}
This is the view controller code
override func viewDidLoad() {
super.viewDidLoad()
let animatedTransitioningObject = TransitioningObject()
animatedTransitioningObject.animateTransition(UIViewControllerContextTransitionin) //I get an error here
// Do any additional setup after loading the view.
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
[[transitionContext containerView] addSubview:toViewController.view];
toViewController.view.alpha = 0;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
fromViewController.view.transform = CGAffineTransformMakeScale(0.1, 0.1);
toViewController.view.alpha = 1;
} completion:^(BOOL finished) {
fromViewController.view.transform = CGAffineTransformIdentity;
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
}
Is how your Animation function should look.
Also if You want a pod that does this for you I would suggest checking out this pod
https://github.com/Ramotion/animated-tab-bar

How do I create a bouncing popover animation like this?

I want to create an animated popover bubble like the one below. With the same expanding/contracting bounce animation. Does anyone know how to go about this? Is is just a UIView with animation? What animation effect is this? Any pointers on how to go about this would be really appreciated. Thanks!
You can use the
Obj-C:
animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:animations completion: method like this:
UIView *animationView = [[UIView alloc] initWithFrame:CGRectMake(50, 90, 100, 50)];
animationView.backgroundColor = [UIColor redColor];
animationView.transform = CGAffineTransformMakeScale(0, 0);
[self.view addSubview:animationView];
[UIView animateWithDuration:0.3
delay:0
usingSpringWithDamping:0.5
initialSpringVelocity:5
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
animationView.transform = CGAffineTransformIdentity;
}
completion:nil];
Swift:
var animationView: UIView = UIView(frame: CGRectMake(50, 90, 100, 50))
animationView.backgroundColor = UIColor.redColor()
animationView.transform = CGAffineTransformMakeScale(0, 0)
self.view!.addSubview(animationView)
UIView.animateWithDuration(0.3, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: .CurveEaseInOut, animations: {() -> Void in
animationView.transform = CGAffineTransformIdentity
}, completion: { _ in })
i think it is UIPopoverPresentationController.
sample:
-(void)showPopover:(UIBarButtonItem*)sender{
if(!_btnController){
_btnController = [[ButtonsViewController alloc] init];
_btnController.delegate = self;
}
if (_popover == nil) {
_btnController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *pc = [ _btnController popoverPresentationController];
pc.barButtonItem = sender;
pc.permittedArrowDirections = UIPopoverArrowDirectionAny;
pc.delegate = self;
[self presentViewController: _btnController animated:YES completion:nil];
} else {
//The color picker popover is showing. Hide it.
[_popover dismissPopoverAnimated:YES];
_popover = nil;
}}

How to animate a floating UIView in ObjectiveC

I am trying to have a UIView animate as a floating object, or as a Balloon :D
The UIView is in the middle of the screen, and I want it to keep floating randomly around its first initiated spot. Not across the screen or anything like that, just floating in the area of 5 pixels around it.
Any suggestions? :D
I tried this:
[UIView animateWithDuration:0.1
delay:0.0
options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction
animations:^{
myCircleUIView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator], [self randomFloatingGenerator]);
}
completion:NULL];
randomFloatingGenerator generates a number between -5 and 5. Problem is, it only executes once, and keeps repeating with the same random values.
EDIT1:
Now I have tried This
-(void)animationLoop{
[UIView animateWithDuration:1.0
animations: ^{ myCircleUIView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator], [self randomFloatingGenerator]); }
completion:
^(BOOL finished) {
[UIView animateWithDuration:1.0
animations:^{ myCircleUIView.transform = CGAffineTransformMakeTranslation(0,0);
}
completion:
^(BOOL finished) {[self animationLoop];}];
}];
But it is still not working, the animation is.... Cracky... I think I am doing some stupid mistake that I need a second set of eyes to help me with.
EDIT2:
Fixed it.
-(void)animationLoop{
CGPoint oldPoint = CGPointMake(myCircleUIView.frame.origin.x, myCircleUIView.frame.origin.y);
[UIView animateWithDuration:1.0
animations: ^{ myCircleUIView.frame = CGRectMake(myCircleUIView.frame.origin.x + [self randomFloatingGenerator], myCircleUIView.frame.origin.y + [self randomFloatingGenerator], myCircleUIView.frame.size.width, myCircleUIView.frame.size.height); }
completion:
^(BOOL finished) {
[UIView animateWithDuration:1.0
animations:^{ myCircleUIView.frame = CGRectMake(oldPoint.x, oldPoint.y, myCircleUIView.frame.size.width, myCircleUIView.frame.size.height);}
completion:
^(BOOL finished) {[self animationLoop];}];
}];
}
Thanks for the help anyone.
EDIT 3:
Someone posted an enhanced code.
#Shamy's solution, improved, fixed and CPU safe.
-(void)animateFloatView:(UIView*)view{
// Abort the recursive loop
if (!view)
return;
CGPoint oldPoint = CGPointMake(view.frame.origin.x, view.frame.origin.y);
[UIView animateWithDuration:0.6
animations: ^{ view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y - 15, view.frame.size.width, view.frame.size.height); }
completion:
^(BOOL finished) {
if (finished) {
[UIView animateWithDuration:0.6
animations:^{ view.frame = CGRectMake(oldPoint.x, oldPoint.y, view.frame.size.width, view.frame.size.height);}
completion:
^(BOOL finished2) {
if(finished2)
[self animateFloatView:view];
}];
}
}];
}
Whenever you want to stop the animation (necessary when leaving the View Controller), call the function using nil, as this:
[self recursiveFloatingAnimation:nil];
Not stoping the animation will cause the recursive loop to run infinitely and overwhelm the CPU stack.
Swift 4
UIView.animate(withDuration: 0.6, delay: 0.1, options: [.autoreverse, .repeat], animations: {
self.frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y - 15, width: self.frame.size.width, height: self.frame.size.height)
},completion: nil )
It will behave in that way. As you are repeating the animation not the function. So it will repeat same animation every time you set at first call. Do it like:
#interface AAViewController ()
#property (nonatomic, strong) UIView * floatingView;
#end
#implementation AAViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_floatingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[_floatingView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:_floatingView];
[self circleUIViewFloating];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Circle UIView floating
- (void) circleUIViewFloating {
[UIView animateWithDuration:2.0
animations:^{
_floatingView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator : 270], [self randomFloatingGenerator:480]);
} completion:^(BOOL finished) {
[self circleUIViewFloating];
}];
}
- (int) randomFloatingGenerator : (int) max{
return arc4random() % max;
}
Here is complete running project for this.
You can achieve the hovering or floating effect using CABasicAnimation.
You will have to include the QuartzCore framework to use this.
Swift 4.2:
import QuartzCore
let hover = CABasicAnimation(keyPath: "position")
hover.isAdditive = true
hover.fromValue = NSValue(cgPoint: CGPoint.zero)
hover.toValue = NSValue(cgPoint: CGPoint(x: 0.0, y: -5.0))
hover.autoreverses = true
hover.duration = 0.8
hover.repeatCount = Float.infinity
myCustomView.layer.add(hover, forKey: "hoverAnimation")
Make sure to remove the animation when the view is no longer being shown.
override func viewWillDisappear(_ animated: Bool) {
// Stop animating when view is going to disappear
myCustomView.layer.removeAllAnimations()
}
-(void)animationLoop{
CGPoint oldPoint = CGPointMake(myCircleUIView.frame.origin.x, myCircleUIView.frame.origin.y);
[UIView animateWithDuration:1.0
animations: ^{ myCircleUIView.frame = CGRectMake(myCircleUIView.frame.origin.x + [self randomFloatingGenerator], myCircleUIView.frame.origin.y + [self randomFloatingGenerator], myCircleUIView.frame.size.width, myCircleUIView.frame.size.height); }
completion:
^(BOOL finished) {
[UIView animateWithDuration:1.0
animations:^{ myCircleUIView.frame = CGRectMake(oldPoint.x, oldPoint.y, myCircleUIView.frame.size.width, myCircleUIView.frame.size.height);}
completion:
^(BOOL finished) {[self animationLoop];}];
}];
}
Swift 2.1 Version Here:
func animateFloatView(view: UIView?) {
// Abort the recursive loop
guard let view = view else { return }
let oldPoint: CGPoint = CGPointMake(view.frame.origin.x, view.frame.origin.y)
UIView.animateWithDuration(0.6, animations: {() -> Void in
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y - 15, view.frame.size.width, view.frame.size.height)
}, completion: {(finished: Bool) -> Void in
if finished {
UIView.animateWithDuration(0.6, animations: {() -> Void in
view.frame = CGRectMake(oldPoint.x, oldPoint.y, view.frame.size.width, view.frame.size.height)
}, completion: {(finished2: Bool) -> Void in
if finished2 {
self.animateFloatView(view)
}
})
}
})
}
Swift 3.1:
func animateFloatView(_ view: UIView?) {
guard let view = view else { return }
let oldYCoordinate = view.center.y
UIView.animate(withDuration: 0.6, animations: {
view.center.y -= 15
}, completion: { _ in
UIView.animate(withDuration: 0.6, animations: {
view.center.y = oldYCoordinate
}, completion: { _ in
self.animateFloatView(view)
})
})
}

Setting the initial values of a UIView animation

I run this code when a swipe event is fired, it shows an arrow zooming in while fading out, as you see I set the location of the image to be the same location as where the swipe is, but it only starts from where the previous touch was(set in the completion block). But at the start of the method I set update the location so why is it animating from the location of the previous touch?
static bool isAnimating;
- (void)animateImageZoom: (UIImageView *)imageView startingAtLocation:(CGPoint)location inDirection: (FadeDirection)direction
{
if (!isAnimating) {
CGRect previousFrame = imageView.frame;
imageView.frame = CGRectMake(location.x, location.y, previousFrame.size.width, previousFrame.size.height);
imageView.hidden = NO;
[UIView animateWithDuration:0.6f
delay:0.3f
options:UIViewAnimationOptionBeginFromCurrentState
animations:^(void) {
isAnimating = YES;
imageView.alpha = 0;
// ZOOM
if (direction == fadeLeft) {
imageView.frame = CGRectMake(location.x,
location.y, 256, 256);
} else if (direction == fadeRight) {
imageView.frame = CGRectMake(location.x,
location.y, 256, 256);
}
}
completion:^(BOOL finished) {
isAnimating = NO;
imageView.frame = CGRectMake(location.x, location.y, previousFrame.size.width, previousFrame.size.height);
imageView.hidden = YES;
imageView.alpha = 0.8f;
}];
}
}

Resources