2011-12-20 6 views
-1

私はそれが欲しい、私がiPadをロールバックするとき、画像は上下にブラインドする。効果は次のようになりますIOSで画像にブラインドダウン効果を与えるにはどうすればよいですか?

http://madrobby.github.com/scriptaculous/combination-effects-demo/ブラインドダウンデモ

どうすればいいですか?

AppleのReflectionの例を試しましたが、すべてのジャイロスコープの動作でイメージを再描画する必要があるため、パフォーマンスの問題がありました。これを行うには

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
tmp = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"galata2.jpg"]]; 
// Do any additional setup after loading the view, typically from a nib. 
NSUInteger reflectionHeight = imageView1.bounds.size.height * 1; 


imageView1 = [[UIImageView alloc] init]; 
imageView1.image = [UIImage imageNamed:@"galata1.jpg"]; 
[imageView1 sizeToFit]; 
[self.view addSubview:imageView1]; 

imageView2 = [[UIImageView alloc] init]; 
//UIImageView *tmp = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"galata2.jpg"]]; 
imageView2.image = [UIImage imageNamed:@"galata2.jpg"]; 

[imageView2 sizeToFit]; 



[self.view addSubview:imageView2]; 

motionManager = [[CMMotionManager alloc] init]; 
motionManager.gyroUpdateInterval = 1.0/10.0; 
[motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] 
            withHandler: ^(CMDeviceMotion *motion, NSError *error){ 

             [self  performSelectorOnMainThread:@selector(handleDeviceMotion:) withObject:motion waitUntilDone:YES]; 

            }]; 

} 

////

- (void)handleDeviceMotion:(CMDeviceMotion*)motion{ 
CMAttitude *attitude = motion.attitude; 
int rotateAngle = abs((int)degrees(attitude.roll)); 
//CMRotationRate rotationRate = motion.rotationRate; 
NSLog(@"rotation rate = [Pitch: %f, Roll: %d, Yaw: %f]", degrees(attitude.pitch), abs((int)degrees(attitude.roll)), degrees(attitude.yaw)); 
int section = (int)(rotateAngle/30); 
int x = rotateAngle % 30; 

NSUInteger reflectionHeight = (1024/30)*x; 
NSLog(@"[x = %d]", reflectionHeight); 
imageView2.image = [self reflectedImage:tmp withHeight:reflectionHeight]; 
} 

////

- (UIImage *)reflectedImage:(UIImageView *)fromImage withHeight:(NSUInteger)height 
{ 
if(height == 0) 
    return nil;  


// create a bitmap graphics context the size of the image 
CGContextRef mainViewContentContext = MyCreateBitmapContext(fromImage.bounds.size.width, fromImage.bounds.size.height); 


// create a 2 bit CGImage containing a gradient that will be used for masking the 
// main view content to create the 'fade' of the reflection. The CGImageCreateWithMask 
// function will stretch the bitmap image as required, so we can create a 1 pixel wide gradient 
CGImageRef gradientMaskImage = CreateGradientImage(1, kImageHeight); 

// create an image by masking the bitmap of the mainView content with the gradient view 
// then release the pre-masked content bitmap and the gradient bitmap 
CGContextClipToMask(mainViewContentContext, CGRectMake(0.0, 0.0, fromImage.bounds.size.width,height), gradientMaskImage); 
CGImageRelease(gradientMaskImage); 

// In order to grab the part of the image that we want to render, we move the context origin to the 
// height of the image that we want to capture, then we flip the context so that the image draws upside down. 
//CGContextTranslateCTM(mainViewContentContext, 0.0,0.0); 
//CGContextScaleCTM(mainViewContentContext, 1.0, -1.0); 


// draw the image into the bitmap context 
CGContextDrawImage(mainViewContentContext, CGRectMake(0, 0, fromImage.bounds.size.width, fromImage.bounds.size.height), fromImage.image.CGImage); 

// create CGImageRef of the main view bitmap content, and then release that bitmap context 
CGImageRef reflectionImage = CGBitmapContextCreateImage(mainViewContentContext); 
CGContextRelease(mainViewContentContext); 

// convert the finished reflection image to a UIImage 
UIImage *theImage = [UIImage imageWithCGImage:reflectionImage]; 

// image is retained by the property setting above, so we can release the original 
CGImageRelease(reflectionImage); 

return theImage; 
} 
+0

これまで行ってきたことは分かりませんが、Core Animationのドキュメントを見ましたか? – Abizern

答えて

1

一つの方法という別の被覆ビューを使用することです。ここでは

は、コードがあります徐々にアニメーションによって高さが変わります。あなたがカバーしたいtheViewと呼ばれるビューを持っている場合は

、カバービューの下theViewを明らかにするために、このような何かを試してみてください。

UIView *coverView = [UIView alloc] initWithFrame:theView.frame]; 
coverView.backgroundcolor = [UIColor whiteColor]; 
[theView.superView addSubView:coverView]; // this covers theView, adding it to the same view that the view is contained in; 
CGRect newFrame = theView.frame; 
newFrame.size.height = 0; 
newFrame.origin.y = theView.origin.y + theView.size.height; 
[UIView animateWithDuration:1.5 
         delay: 0.0 
        options: UIViewAnimationOptionRepeat 
       animations:^{ 
        coverView.frame = newFrame; 
       } 
       completion:nil 
       ]; 

これは、ビューをカバーして、フレームOVを変更することによって、それを公開すべきですカバーは、高さを変えながら下に移動します。

私はコードを試していませんが、これは盲目的な効果を作り出すために取ることができる1つの方向です。私はよく似たようなコードを使いましたが、それはとても使いやすいです。また、コアアニメーションを知る必要もありません。

+0

ですがアニメーションです。私はアニメ化したくありません。私が望むのは、ジャイロスコープの助けを借りて、デバイスを回転させ、高さを計算し、マスクでイメージを再描画することです。 – Burak

+0

大変申し訳ございません。唯一必要なことは、アルファグラデーションを使用してイメージをマスクし、ロールアクションでこのグラデーションの高さを変更することです。レンチキュラー写真のようになります。 – Burak

+0

質問を編集したい場合があります。 – Jim