8

UIImageをその範囲内で再描画することにより、UIImageを反転/反射/回転する方法を知っています。

- (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の「フリップ/リフレクト」効果を作成するにはどうすればよいですか。できれば、UIViewの中心を以前と同じ位置に維持します。

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

4

2 に答える 2

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アニメーションに使用されます。さまざまなタイプのアニメーションのオプションを取得する場所。

于 2012-05-21T12:42:18.727 に答える
1

によって任意のビューの「スクリーンショット」を作成できます

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

次に、UIImageを反転し、ビューの下に結果の画像を含むUIImageViewを追加します。

于 2012-05-21T12:45:38.887 に答える