Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Tutorials

Reply
 
LinkBack Thread Tools Display Modes
Old 08-18-2011, 01:20 PM   #1 (permalink)
Registered Member
 
blackbook1991's Avatar
 
Join Date: Aug 2011
Posts: 20
blackbook1991 is on a distinguished road
Send a message via Yahoo to blackbook1991
Default UIImage Reflection Tutorial

Hi!

I'd like to share to you my simple ImageReflection project. I placed some explanation according to my understanding so please be gentle me with me. I used this feature so that my image carousel (on another project) would look cool. This project is something that would give you like this:


LET'S START!
1. In XCode, create a View-based Application. Name your project ImageReflection.
2. Add to your project your image. As for me, my image is named spongebob.png.
3. In your ImageReflectionViewController.m, uncomment or create the loadView method and modify it that it would look like this:

Code:
- (void) loadView {
	[super loadView];
	self.view.backgroundColor = [UIColor blackColor];

	// Modify the image name accordingly
	UIImage *image = [UIImage imageNamed:@"spongebob.png"];
	
	UIImageView *imageView = [[UIImageView alloc]initWithImage:image];

	CGImageRef imageToSplit = image.CGImage;
        // I'm using the lower 1/3 of the image only
	CGImageRef partOfImageAsCG = CGImageCreateWithImageInRect(imageToSplit, CGRectMake(0,(image.size.height*2)/3,image.size.width, image.size.height/3));
        // Create an UIImage instance of the image part
	UIImage *partOfImage = [UIImage imageWithCGImage:partOfImageAsCG];
	// Flip the UIImage mirrored upside-down
        UIImage* flippedImage = [UIImage imageWithCGImage:partOfImage.CGImage scale:1.0 orientation:  UIImageOrientationDownMirrored];
	
	UIImageView *reflectionView = [[UIImageView alloc]initWithImage:flippedImage];
	reflectionView.frame = CGRectMake(0, image.size.height, image.size.width, image.size.height/2);

        // Initialize ImageContext with the combined sizes of the imageView (original image) and the reflectionView
	UIGraphicsBeginImageContext(CGSizeMake(imageView.image.size.width,imageView.image.size.height+reflectionView.image.size.height));  
	// Creates an CGRect with the imageView content
	CGRect imageRect = CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height);
        // Creates an CGRect with the reflectionView content
	CGRect reflectionRect = CGRectMake(0, imageView.image.size.height, reflectionView.image.size.width, reflectionView.image.size.height);
	//shows the imageView at full size 
	[imageView.image drawInRect:imageRect]; 
	//displays the reflection with 0.5 transparent
        [reflectionView.image drawInRect:reflectionRect blendMode:kCGBlendModeScreen alpha:0.5];  
	
        // Creates an UIImage instance of the resulting image context
	UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();  
	UIGraphicsEndImageContext();

	// Creates the resulting view
	UIImageView *resultingView = [[UIImageView alloc]initWithImage:resultingImage];

        // Displays the image view on screen
	[self.view addSubview:resultingView];
}
4. Build and Run.
5. Celebrate! You're done!

You can download the project here.
__________________
Enjoy All The Way!
blackbook1991 is offline   Reply With Quote
Reply

Bookmarks

Tags
image, reflection, uiimage

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 468
13 members and 455 guests
alexeir, David-T, Dj_kades, foslock, iAppDeveloper, jeroenkeij, LunarMoon, Mijator, pipposanta, QuantumDoja, robsmy, sacha1996, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,129
Posts: 402,928
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0