HomeStoreForumsWikiiPhone Native AppsiPhone Apps modmyifone Downloadsmodmyifone Links








Cell Phone Reception

Go Back   iPhone Forums at ModMyiFone.com - iPhone | iPod Touch, news, apps, themes. > 3rd Party Apps For iPhone | iPod Touch > iPhone / iPod Touch SDK | Development Discussion
Register FAQ Members List READ THIS Today's Posts Mark Forums Read

iPhone / iPod Touch SDK | Development Discussion SDK questions. A place for iPhone developers to post code snippets, discuss creating iPhone apps, and any other iPhone developing.


MMi Super Contest | 30 winners! Over $1500 in Prizes! Enter Today!

Discuss AppStore Apps! | MMi Cydia Repo Download Stats

Get more out of ModMyiFone by joining our free community. By registering you get privileges to download files from our downloads section and you may also post your questions in our forums! It's fast, free, and easy!

2.0 Unlock|Jailbreak OS X / Windows | iPhone 3G Detailed Review w/Pics! | Developers - Port Your Apps to 2.0
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-28-2007, 02:57 PM
Developer
 
Join Date: Jul 2007
Location: Chicago, IL
Posts: 130
Thanks: 0
Thanked 18 Times in 13 Posts
UIView Subclass with Rotation & 3D Flipping

Here is a first version of a code sample snippet of a class that has both 2D rotation and 3D flipping of the view. It also handles some basic form of moving the view, in this case moving the view off the screen so it can also be removed from it's superview.

It's something I tweaked with a lot and eventually got working to the level I was happy with for iBlackjack. I made some changes to that class before posting it here, no need for my logic for displaying what card it is, etc to clutter up the example.

I'm not 100% happy with the results of the rotation, because it makes the view distort when being moved after being rotated. But hopefully I can find a solution to this.

Here is a line of code to add it to another view:

Code:
McView *myMcView = [[[McView alloc] initWithFrame: CGRectMake(10.0f, 10.0f, 60.0f, 80.0f) showFace:YES] autorelease];
[myUIView addSubview: myMcView];
Attached Files
McView.h (1.3 KB, 75 views)
McView.m (5.5 KB, 99 views)
__________________
Patrick McCarron
iPhone Software Engineer @ Mobileage, Inc
Cocoa Touch Apps Developed: Blackjack 21 & Shanghai Mahjong

Last edited by McCarron; 12-28-2007 at 03:27 PM.
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #2 (permalink)  
Old 12-28-2007, 03:02 PM
Moderator
 
Join Date: Jul 2007
Device + Firmware: Iphone 3G
Operating System: Windows XP
Location: Saint Louis, MO
Posts: 523
Thanks: 51
Thanked 41 Times in 38 Posts

can't wait....
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #3 (permalink)  
Old 12-28-2007, 03:28 PM
Developer
 
Join Date: Jul 2007
Location: Chicago, IL
Posts: 130
Thanks: 0
Thanked 18 Times in 13 Posts

Quote:
Originally Posted by stlcaddie View Post
can't wait....
wait is over, posted it early. I can't claim it compiles, but it should.
__________________
Patrick McCarron
iPhone Software Engineer @ Mobileage, Inc
Cocoa Touch Apps Developed: Blackjack 21 & Shanghai Mahjong
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #4 (permalink)  
Old 12-29-2007, 03:20 AM
drunknbass's Avatar
the kanye west of programming
 
Join Date: Jul 2007
Posts: 378
Thanks: 0
Thanked 47 Times in 38 Posts

you know there are alot easier ways to move a view and flip a page etc.
i posted code a lonnnng time ago on idevdocs.com and its also on my site here

http://www.monsterandfriends.com/?q=node/36
__________________

www.monsterandfriends.com The iPhone Developers Resource!
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #5 (permalink)  
Old 12-29-2007, 07:00 AM
Developer
 
Join Date: Jul 2007
Location: Chicago, IL
Posts: 130
Thanks: 0
Thanked 18 Times in 13 Posts

Quote:
Originally Posted by drunknbass View Post
you know there are alot easier ways to move a view and flip a page etc.
i posted code a lonnnng time ago on idevdocs.com and its also on my site here

http://www.monsterandfriends.com/?q=node/36
I tried the oglflip method, and it was generating some nasty effects for me. Anything I was flipping with transparent or alpha blended pixels in my views were turning black when flipping.

Also using oglflip I have to create two image views to do the transition. So each playing card in my game then takes up 2x the memory than a single card would using the method I went with.

I tried to post up a question on idevdocs.com about it, but the admins wont validate my account.

Also, I don't see a way in that website to move the image. How would you do it other than altering the rectangle's origin point using CoreAnimation? I can't see it being much easier than that, but I want to try something else to see if it works after doing a rotate on an image without distorting.
__________________
Patrick McCarron
iPhone Software Engineer @ Mobileage, Inc
Cocoa Touch Apps Developed: Blackjack 21 & Shanghai Mahjong

Last edited by McCarron; 12-29-2007 at 07:14 AM.
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #6 (permalink)  
Old 12-29-2007, 12:06 PM
NetMage's Avatar
Developer
 
Join Date: Aug 2007
Device + Firmware: iPhone 1.1.3
Operating System: Windows XP / OS X
Location: Virginia
Posts: 1,103
Thanks: 33
Thanked 179 Times in 145 Posts

If you send them an email, they'll fix your account.

They were having trouble with validation.

Why do you need to create another view of each card for oglFlip?
__________________
Starlight Computer Wizardry
Pocket-sized Development
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #7 (permalink)  
Old 12-29-2007, 12:17 PM
Developer
 
Join Date: Jul 2007
Location: Chicago, IL
Posts: 130
Thanks: 0
Thanked 18 Times in 13 Posts

Quote:
Originally Posted by NetMage View Post
If you send them an email, they'll fix your account.

They were having trouble with validation.

Why do you need to create another view of each card for oglFlip?
I did, no response from them. I sent emails and PMs via the forum, no dice. I've decided to contribute here instead, much larger community so I think it's got more promise.

As far as the memory issue. There is maybe another way to be more optimized, but I never looked into it since the effect is so crappy with the black replacement of alpha transparent pixels. After I couldn't fix the graphical glitch and confirmed with another developer he saw the same problem, I never looked into optimizing it.

For the OGLFlip it's a transition animation, it has to go from one uiview sub-class to another. So I need to transition from one image (back of the card) to the other image (front of the card). So each instance of the class has to have two UIImageViews to perform the flip.

Instead the method I used here, is it only changes the layer image's contents when requested. So it does it while the card is flipped flat and unviewable, by calling to reset the layer's contents during a call to animationDidStop. This takes far less memory, and doesn't require two extra UIImageViews to transition between.

Sure OGLFlip takes care of the whole "reversed" image problem without having to use CoreGraphics to flip the image around, but the ugly graphical glitch is not worth it. Depending on the card theme I was using, some were just horrible looking when being flipped.
__________________
Patrick McCarron
iPhone Software Engineer @ Mobileage, Inc
Cocoa Touch Apps Developed: Blackjack 21 & Shanghai Mahjong
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #8 (permalink)  
Old 01-02-2008, 02:52 AM
drunknbass's Avatar
the kanye west of programming
 
Join Date: Jul 2007
Posts: 378
Thanks: 0
Thanked 47 Times in 38 Posts

well you dont have to follow my code 100%. for animations like that you should be using layerkit to handle the animations.
also you even having both images in memory till the animation is finished should be fine as long as you release what you dont need after youre done with it.
__________________

www.monsterandfriends.com The iPhone Developers Resource!
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #9 (permalink)  
Old 01-02-2008, 08:53 AM
Developer
 
Join Date: Jul 2007
Location: Chicago, IL
Posts: 130
Thanks: 0
Thanked 18 Times in 13 Posts

Yeah as I stated, I never worked on optimizing it since the effect was garbage. If I had pictures of the nasty black artifacts I'd show you, oglflip is obviously not perfect. I'd prefer to use CoreAnimation transforms for flipping. Gives me much more control over what happens after the animation.

Also the animations I'm doing in the class for moving, etc is a simple CoreAnimation (LayerKit) animator proxy. It's the same thing as working directly with the layer, works great for simple effects like moving, scaling, etc.

BUT because the iPhone uses an early version of CoreAnimation it may be buggy and may be causing my corruption issue when moving a view after it's been rotated. I'll have to try direct Layer manipulations instead to see if it fixes the problem.
__________________
Patrick McCarron
iPhone Software Engineer @ Mobileage, Inc
Cocoa Touch Apps Developed: Blackjack 21 & Shanghai Mahjong
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #10 (permalink)  
Old 01-02-2008, 08:48 PM
CyberGreg's Avatar
Retired Moderator
 
Join Date: Jul 2007
Device + Firmware: iPhone 3G/Touch 2.0
Operating System: OS 10.6
Posts: 1,036
Thanks: 55
Thanked 175 Times in 129 Posts

Quote:
Originally Posted by drunknbass View Post
you know there are alot easier ways to move a view and flip a page etc.
i posted code a lonnnng time ago on idevdocs.com and its also on my site here

http://www.monsterandfriends.com/?q=node/36
...and it looks awesome in my new iSwitcherAE, many many thanks!!!!!
__________________
White 3G
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #11 (permalink)  
Old 01-03-2008, 01:48 AM
drunknbass's Avatar
the kanye west of programming
 
Join Date: Jul 2007
Posts: 378
Thanks: 0
Thanked 47 Times in 38 Posts

Quote:
Originally Posted by CyberGreg View Post
...and it looks awesome in my new iSwitcherAE, many many thanks!!!!!
cool. glad it helped

Quote:
Originally Posted by McCarron View Post
I did, no response from them. I sent emails and PMs via the forum, no dice. I've decided to contribute here instead, much larger community so I think it's got more promise.

As far as the memory issue. There is maybe another way to be more optimized, but I never looked into it since the effect is so crappy with the black replacement of alpha transparent pixels. After I couldn't fix the graphical glitch and confirmed with another developer he saw the same problem, I never looked into optimizing it.

For the OGLFlip it's a transition animation, it has to go from one uiview sub-class to another. So I need to transition from one image (back of the card) to the other image (front of the card). So each instance of the class has to have two UIImageViews to perform the flip.

Instead the method I used here, is it only changes the layer image's contents when requested. So it does it while the card is flipped flat and unviewable, by calling to reset the layer's contents during a call to animationDidStop. This takes far less memory, and doesn't require two extra UIImageViews to transition between.

Sure OGLFlip takes care of the whole "reversed" image problem without having to use CoreGraphics to flip the image around, but the ugly graphical glitch is not worth it. Depending on the card theme I was using, some were just horrible looking when being flipped.
you can use regular affine transforms, but layerkit/CA supposedly works in opengl and other things to help accelerate the animations.
__________________

www.monsterandfriends.com The iPhone Developers Resource!

Last edited by drunknbass; 01-03-2008 at 01:48 AM. Reason: Automerged Doublepost
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #12 (permalink)  
Old 01-03-2008, 11:11 AM
Developer
 
Join Date: Jul 2007
Location: Chicago, IL
Posts: 130
Thanks: 0
Thanked 18 Times in 13 Posts

Quote:
Originally Posted by drunknbass View Post
you can use regular affine transforms, but layerkit/CA supposedly works in opengl and other things to help accelerate the animations.
Yeah I used those regular affine transforms in older versions, before I got my hands on CoreAnimation documentation, I agree they are very sluggish.

I'm hoping it's a problem with the version of LayerKit we're using on the iPhone, since it's clearly not the final version of CoreAnimation.

Having a slight rotation on my iBlackjack playing cards and betting chips makes the game look much better and more "natural."
__________________
Patrick McCarron
iPhone Software Engineer @ Mobileage, Inc
Cocoa Touch Apps Developed: Blackjack 21 & Shanghai Mahjong
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
Reply

  iPhone Forums at ModMyiFone.com - iPhone | iPod Touch, news, apps, themes. > 3rd Party Apps For iPhone | iPod Touch > iPhone / iPod Touch SDK | Development Discussion

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
Forum Jump

ModMyMoto.com - ModMyGPhone.com - ModMyiFone.com - Dedicated Server Hosting by SingleHop - iPhone Wallpapers - iPhone forums | iPod touch forums, news, themes, apps, games, unlock, jailbreak community - ModMyiFone.com RSS Feeds - Contact Us - Link to us - Archive - Privacy Statement - - Top
Copyright © 2007-08 by ModMy, LLC. All rights reserved. You may not copy anything on this site unless you link to the original.
All times are GMT -6. The time now is 07:13 PM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
ModMyiFone.com is an independent publication and has not been authorized, sponsored, or otherwise approved by Apple, Inc or Cisco Systems, Inc. The information contained on this site is for educational purposes only.
Forum skin by poetic_folly