iPhone iOS how to flip/reflect any UIView in – place?

I know how to flip/reflect/rotate a UIImage by re-drawing it within it’s bounds.

- (IBAction)reflectImageView:(UIImageView)imageView {

    UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 0.0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextTranslateCTM(context, 0.0, -imageView.bounds.size.height);


   [imageView.layer renderInContext:context];
    imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

}

But how do I create a “flip/reflect” effect for any UIView, preferably keeping it’s center in the same position as before?

  • Toggling AirPlane mode in iOS Programmatically
  • Is Swift vulnerable to code injection?
  • How to cache an AVPlayerItem (Video) for reuse in a UITableview
  • XCode 5 Storyboard Internal Inconsistencies
  • XMLRPC-iOS for iOS project
  • SWIFT UITableViewCell with corner radius and shadow
  • Thank you!

    2 Solutions Collect From Internet About “iPhone iOS how to flip/reflect any UIView in – place?”

     [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.75];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.activeView cache:YES];
        //        [self.activeView removeFromSuperview];
        [UIView commitAnimations];
    
        NSNumber* isReflected = [self.activeView.attributedView.attributes valueForKey:kIsReflected];
        if(isReflected.boolValue)
        {
            self.activeView.transform = CGAffineTransformMakeScale(1,1);
            [self.activeView.attributedView.attributes setValue: [NSNumber numberWithBool:NO]  forKey:kIsReflected];
        }else {
            //do reflection
            self.activeView.transform = CGAffineTransformMakeScale(-1,1);
            [self.activeView.attributedView.attributes setValue: [NSNumber numberWithBool:YES]  forKey:kIsReflected];
        }
    

    Above code is used for UIView Animation. Where you will get an options for various type animation.

    You can make a “screenshot” of any View by

    UIGraphicsBeginImageContext(self.view.frame.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    and then flip the UIImage and add a UIImageView with the resulting Image below the view.