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 Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-31-2011, 02:29 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 48
cybohemia is on a distinguished road
Default animating the re-positioning of an image in an UIImageView

I am trying to display an image in an UIImageView where the UIImageView only takes up half of the iPhone screen and shows just part of the image (which is full screen sized), but after the user presses a button, the UIImageView animates and expands to the full screen and the image re-positions to show its entire content, properly centered (it was off-centered when shown partially).

I've tried using drawInRect which solved me the first part of my problem (showing just a part of the image) but, I don't know how to animate the image movement within the UIImageView when it animates to take up the full screen.

I can get the UIImageView to animate from half-screen to full-screen but when I try to re-position of the image inside the animation block it just pops over to the new position rather than animate over.

Would anyone have any idea as to how one should go about such a task?

Thanks!
cybohemia is offline   Reply With Quote
Old 03-31-2011, 02:52 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Cleveland, Ohio
Posts: 26
Panther is on a distinguished road
Default

I think this achieves what you're describing.

Code:
    //Setup
    imageView.image = myImage;
    imageView.frame = halfTheScreen;
    imageView.clipsToBounds = YES;
    imageView.contentMode = UIViewContentModeTop;
    
    //To animate
    [UIView animateWithDuration:duration animations:^{
        imageView.frame = entireScreen;
    }];
Panther is offline   Reply With Quote
Old 04-01-2011, 04:09 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 48
cybohemia is on a distinguished road
Default

Thanks for the suggestion, Panther! One thing that I didn't think would be a factor but I can't seem to get to work with your approach is to have the half image show a portion of the image that is offset from the top. That is, I don't want to show the top half of the image but a middle section (the 2nd quarter and 3rd quarter of the image):



The left image is how things start - only half of the full image is shown, the half being the middle section of the image. I then want to animate to the full image with the half originally show sliding into its proper position in the middle of the image.

The only way I worked out how to show the middle section on the top of the screen is to use drawRect but it pops instantly to its final position - rather than smoothly animating there - when I try to animate into a full screen display of the full image.

When I fiddle with the numbers in your approach, the final image is aways offset by the amount the image is originally offset by (although I want to set the offset to 0 when the full image is shown).

Are there ways to offset the image and then un-doing the offset with your appoach?

Thanks!



Quote:
Originally Posted by Panther View Post
I think this achieves what you're describing.

Code:
    //Setup
    imageView.image = myImage;
    imageView.frame = halfTheScreen;
    imageView.clipsToBounds = YES;
    imageView.contentMode = UIViewContentModeTop;
    
    //To animate
    [UIView animateWithDuration:duration animations:^{
        imageView.frame = entireScreen;
    }];
cybohemia is offline   Reply With Quote
Old 04-02-2011, 07:35 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Cleveland, Ohio
Posts: 26
Panther is on a distinguished road
Default

Just change the content mode in my snippet to UIViewContentModeCenter and make your image the same size as the image view's final size. The diagram was very helpful, by the way.
Panther is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, image, uiimageview

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 369
12 members and 357 guests
condor304, dansparrow, dre, ilmman, LezB44, michelle, Objective Zero, samdanielblr, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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