2012-05-21 25 views
8

Sé cómo voltear/reflejar/rotar un UIImage volviéndolo a dibujar dentro de sus límites.iPhone iOS ¿cómo voltear/reflejar cualquier UIView en el lugar?

- (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(); 

} 

Pero ¿Cómo se crea un efecto "flip/reflejar" para cualquier UIView, preferentemente manteniendo su centro en la misma posición que antes?

¡Gracias!

+0

su pregunta es mi respuesta sobre cómo rotar la imagen: P gracias +1 –

Respuesta

4
[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]; 
    } 

El código anterior se utiliza para UIView Animation. Donde obtendrás opciones para varios tipos de animación.

+0

Esto reproduce la animación, pero la vista sigue siendo la misma. Si elimino la vista de la supervista, no queda nada en su lugar. La animación es genial, pero necesito mostrar realmente la imagen reflejada de la vista –

1

se puede hacer una "pantalla" de cualquier View de

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

y luego darle la vuelta al UIImage y añadir un UIImageView con la imagen resultante debajo de la vista.

+0

Me gustaría que el usuario continúe interactuando con la vista, incluso una vez que se refleja. Mostrar una UIImageView en lugar de una vista normal es una opción, pero puede requerir demasiada información al usuario sobre cuándo la vista es "real" y cuándo es una "imagen" –

+0

¡Qué gran fragmento! Todavía funciona como un encanto 4 años después –

Cuestiones relacionadas