4

私はこの問題に完全に困惑しています、そしてそれは私を狂わせるほど単純でなければなりません。

私はこのアップルリフレクションチュートリアルを使用しています。

AppleReflectionの例

それらには、上から下に表示される画像勾配があります。

  • 左から右にグラデーションを作成するにはどうすればよいですか
  • 画像を水平方向に反転するにはどうすればよいですか。彼らの例では、画像を垂直方向に反転します。

何か助けはありますか?

//The gradient code is here but I don't know what should be the gradient start / end points
CGImageRef CreateGradientImage(int pixelsWide, int pixelsHigh)
{
.....
gradientStartPoint = CGPointZero;
        gradientEndPoint = CGPointMake(0, pixelsHigh);
}

//similarly I know the image flip happens here but for life of me I cannot make it flip horizontally

- (UIImage *)reflectedImage:(UIImageView *)fromImage withHeight:(NSUInteger)height
{
.....
CGContextTranslateCTM(mainViewContentContext, 0.0, height);
        CGContextScaleCTM(mainViewContentContext, 1.0, -1.0);
}
4

1 に答える 1

4

これを試して:

//horizontal gradient
CGImageRef CreateGradientImage(int pixelsWide, int pixelsHigh)
{
    .....
    gradientStartPoint = CGPointZero;
    gradientEndPoint = CGPointMake(pixelsWide, 0);
}

//horizontal flip

- (UIImage *)reflectedImage:(UIImageView *)fromImage withWidth:(NSUInteger)width
{
    .....
    CGContextTranslateCTM(mainViewContentContext, width, 0,0);
    CGContextScaleCTM(mainViewContentContext, -1.0, 1.0);
}

水平フリップの場合、高さではなく幅を指定する必要があるため、新しいメソッドを追加する必要があります。

幸運を!

編集1:

グラデーションを取得するには、reflectedImage:withWidthに別の変更を追加する必要があります。

- (UIImage *)reflectedImage:(UIImageView *)fromImage withWidth:(NSUInteger)width
{
    .....
    CGImageRef gradientMaskImage = CreateGradientImage(width, 1);
    .....
}
于 2013-01-16T03:45:55.390 に答える