Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9259697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:43:01+00:00 2026-06-18T12:43:01+00:00

I’ve been implementing a simple FlipView in iOS : A UIView that contains two

  • 0

I’ve been implementing a simple FlipView in iOS : A UIView that contains two subviews, displaying one at a time, and when you click on it, it flips them.
I’m using the following to animate the flipping.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    @synchronized(self){
        if(!self.flipping){
            self.flipping = YES;
            UIView *toView = self.currentView == self.primaryView ? self.secondaryView : self.primaryView;            
            [UIView transitionFromView:self.currentView toView:toView duration:self.speed options:UIViewAnimationOptionTransitionFlipFromLeft|UIViewAnimationOptionCurveEaseInOut completion:^(BOOL finished) {
                [self.currentView removeFromSuperview];
                self.currentView = toView;
                self.flipping = NO;
            }];                
        }
    }
}

Pretty straight forward, right ?

But what bugs me is that, while the views are flip, the flipped content is darkened. Which shows, against a light background.

Would anyone knows a solution to have the exact same animation, but without the darkening (<= is that even a word ?)

Thanks in advance !

PS : I’m targeting IOS 5 and above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:43:03+00:00Added an answer on June 18, 2026 at 12:43 pm

    I succeeded, getting inspiration in the code I found here http://www.mycodestudio.com/blog/2011/01/10/coreanimation/ (and he, himself, took inspiration from http://www.mentalfaculty.com/mentalfaculty/Blog/Entries/2010/9/22_FLIPPIN_OUT_AT_NSVIEW.html)

    Anyway, what I do spin between two views.

    - (void)flip{
        @synchronized(self){
            if(!self.flipping){
                self.flipping = YES;
    
                UIView *bottomView = self.currentView == self.primaryView ? self.secondaryView : self.primaryView;
                CALayer *top = self.currentView.layer;
                CALayer *bot = bottomView.layer;
    
                CAAnimation *topAnimation = [self flipAnimationWithDuration:self.speed/2.0 forLayerBeginningOnTop:YES scaleFactor:1];
                CAAnimation *bottomAnimation = [self flipAnimationWithDuration:self.speed/2.0 forLayerBeginningOnTop:NO scaleFactor:1];
    
                CGFloat zDistance = 1500.0f;
                CATransform3D perspective = CATransform3DIdentity;
                perspective.m34 = -1. / zDistance;
                top.transform = perspective;
                bot.transform = perspective;
    
                topAnimation.delegate = self;
                [CATransaction setCompletionBlock:^{
                    [top removeAllAnimations];
                    [self.currentView removeFromSuperview];
                    self.currentView = bottomView;
                    [self addSubview:bottomView];
    
                    [CATransaction setCompletionBlock:^{
                        self.flipping = NO;
                        [bot removeAllAnimations];
                    }];
                    [CATransaction begin];
    
                    [bot addAnimation:bottomAnimation forKey:@"flip"];
    
                    [CATransaction commit];
                }];
                [CATransaction begin];
                [top addAnimation:topAnimation forKey:@"flip"];
    
                [CATransaction commit];
            }
        }
    }
    
    -(CAAnimation *)flipAnimationWithDuration:(NSTimeInterval)aDuration forLayerBeginningOnTop:(BOOL)beginsOnTop scaleFactor:(CGFloat)scaleFactor
    {
        // Rotating halfway (pi radians) around the Y axis gives the appearance of flipping
        CABasicAnimation *flipAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
        CGFloat startValue = beginsOnTop ? 0.0f : M_PI/2;
        CGFloat endValue = beginsOnTop ? -M_PI/2 : 0.0f;
        flipAnimation.fromValue = [NSNumber numberWithDouble:startValue];
        flipAnimation.toValue = [NSNumber numberWithDouble:endValue];
    
        // Shrinking the view makes it seem to move away from us, for a more natural effect
        // Can also grow the view to make it move out of the screen
        CABasicAnimation *shrinkAnimation = nil;
        if (scaleFactor != 1.0 ) {
            shrinkAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
            shrinkAnimation.toValue = [NSNumber numberWithFloat:scaleFactor];
    
            // We only have to animate the shrink in one direction, then use autoreverse to "grow"
            shrinkAnimation.duration = aDuration * 0.5;
            shrinkAnimation.autoreverses = YES;
        }
    
        // Combine the flipping and shrinking into one smooth animation
        CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
        animationGroup.animations = [NSArray arrayWithObjects:flipAnimation, shrinkAnimation, nil];
    
        // As the edge gets closer to us, it appears to move faster. Simulate this in 2D with an easing function
        animationGroup.timingFunction = [CAMediaTimingFunction functionWithName:beginsOnTop?kCAMediaTimingFunctionEaseIn:kCAMediaTimingFunctionEaseOut];
        animationGroup.duration = aDuration;
    
        // this really means keep the state of the object at whatever the anim ends at
        // if you don't do this then it reverts back to the original state (e.g. brown layer)
        animationGroup.fillMode = kCAFillModeForwards;
        animationGroup.removedOnCompletion = NO;
    
        return animationGroup;
    }
    

    The two views are named primaryView and secondaryView. You can use any view, (ImageView, text view…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.