2012-05-21 29 views
8

Tôi biết cách lật/phản ánh/xoay UIImage bằng cách vẽ lại nó trong giới hạn của nó.iPhone iOS làm thế nào để lật/phản ánh bất kỳ UIView tại chỗ?

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

} 

Nhưng làm cách nào để tạo hiệu ứng "lật/phản chiếu" cho bất kỳ UIView nào, tốt nhất là giữ trung tâm ở cùng vị trí như trước?

Cảm ơn bạn!

+0

câu hỏi của bạn là câu trả lời về cách xoay hình ảnh: P thanks +1 –

Trả lời

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

Mã trên được sử dụng cho hoạt ảnh UIView. Nơi bạn sẽ nhận được một tùy chọn cho các loại hình ảnh động khác nhau.

+0

Thao tác này sẽ phát hình động nhưng chế độ xem vẫn giữ nguyên. Nếu tôi xóa chế độ xem khỏi trình giám sát, không có gì còn lại ở vị trí đó. Các hình ảnh động là rất mát mẻ, nhưng tôi cần phải thực sự hiển thị hình ảnh phản chiếu của chế độ xem –

1

Bạn có thể thực hiện một "ảnh chụp màn hình" của bất kỳ Xem theo

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

và sau đó lật UIImage và thêm một UIImageView với hình ảnh kết quả dưới đây xem.

+0

Tôi muốn người dùng tiếp tục tương tác với chế độ xem, ngay cả khi nó được phản ánh. Việc hiển thị UIImageView thay cho chế độ xem thông thường là một tùy chọn, nhưng có thể yêu cầu quá nhiều giáo dục người dùng đến khi chế độ xem là "thực" và khi đó là "hình ảnh" –

+0

Thật là một đoạn trích tuyệt vời! Vẫn làm việc như một say mê 4 năm sau –

Các vấn đề liên quan