2012-05-21 3 views
8

UIImageをその枠内で再描画することによって、UIImageを反転/回転/回転させる方法を知っています。iPhone iOSどのようにUIViewをインプレースで反転/反映するのですか?

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

} 

しかし、どのようにして、以前と同じ位置に中心を保持することが望ましいですか?すべてのUIViewに対して「フリップ/リフレクション」エフェクトを作成するにはどうすればよいですか?

ありがとうございました!

+0

あなたの質問は画像の回転方法に関する私の答えです:Pありがとう+1 –

答えて

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

上記のコードは、UIViewアニメーションに使用されています。さまざまなタイプのアニメーションのオプションを取得する場所。

+0

これはアニメーションを再生しますが、ビューは変わりません。スーパービューからビューを削除すると、そこには何も残っていません。アニメーションは非常にクールですが、実際にビューの鏡像を表示する必要があります –

1

あなたは

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

ことによって、任意のビューの「スクリーンショット」を作成してからUIImageを反転し、ビューの下に、結果として得られる画像でUIImageViewを追加することができます。

+0

ビューに反映されていても、ユーザーがビューとのやり取りを続けてほしいです。通常のビューの代わりにUIImageViewを表示することもできますが、ビューが「本当の」ときと「イメージ」のときにユーザー教育が必要になることがあります –

+0

どのような素晴らしいスニペットですか? 4年後の魅力のような作品 –

関連する問題