How to create image slideshow effect - iphone

I m trying to do slideshow effect in iPhone as like in iTunes. One Image at the middle and the others at the left and ride side arranged in the manner of floppies in rack. but I not even a single clue for that. Can any one help me out?

I'm guessing that you're talking about "coverflow" rather than "slideshow"... if that's right, there are some libraries to help you: here's one I found by searching for "coverflow replacement":
http://apparentlogic.com/openflow/

You can achieve this effect using the .transform property of CALayers. All iPhone UIViews have a CALayer, and you can apply 3D perspective transformations using a transform matrix like this:
CATransform3D m = CATransform3DIdentity;
m.m34 = -0.006;
[[containerView layer] setSublayerTransform: m];
The views within containerView will now have a perspective distortion applied! Instant coverflow affect. Just move the views to the left and right by changing their frames.

Related

Draw triangular UIButton on iPhone?

What would be the way to draw a triangular button on the iPhone. It would be nice if I could also change its parameters (backgroundcolor, font etc..) as with the regular buttons.
Ideally I would like equilateral triangles.
take a look at this post: http://iphonedevelopment.blogspot.com/2010/03/irregularly-shaped-uibuttons.html
You could transform you button/view using core animation 3d transform. I am not sure how it will look like inside of it. but you surely can get a triangle form view.
You can apply a rotation in 3D (arround X or Y axis, not Z) with a large enough angle that it looks like a triangle.
An alternative approach is to make it look like triangular. You probably not need it TO BE triangular. So, maybe by setting a triangular look like image or maybe by hiding part of the button with (2D) rotated view or layer.
If you are not changing too much the background images of your buttons, I suggest to put in the resources, some .png file you create using photoshop for example, in which the triangular part has full opacity and the remaining areas are full transparent.
Then create UIImage using the method : [UIImage imageNamed:file_path_inside_resources_folder] and set it as background image for your button.
Note that you need to do the work only once, since the UIButton will resize the picture according to its own frame dimensions.
Regards
Meir Assayag

implementing stretchable dialog borders in iphone sdk

I want to implement dialog borders that scale to the size I require the dialog to be. Perhaps there is a better more conventional name for this sort of thing. If there is, if someone would edit the title, that'd be great.
Anyhow, I'd like to do this so I can have dialogs of any size without the visual artifacts that come with scaling border art to small, large, or wacky unproportional dimentions. I have a few ideas on how this is done, but am not sure which is better for iphone. I have a few questions.
1) Should I make a containing view object that basically overloads its drawRect method and draws the images where they should be at their appropriate scale when the method is called, or should I main a containing view object that simply contains 8 UIImageViews? I suspect the latter approach won't work if I need to actively scale the resulting dialog class like in an animation.
1b) If overloading drawRect is the way to go, does someone have some sample code or a link to an example that demonstrates drawing an image directly from drawRect()?
2) Is it generally better to create
a) a 3 x 3 image where the segments are in their appropriate 1x1 grid of the image? If so, is it simple to draw from a portion of this image onto my target view in drawRect (if the former assumption is correct that I should use drawRect)?
b) The pieces separately in 8 different files?
UPDATE:
To clarify, the idea is to take any customized border art and be able to stretch the 2nd, 4th, 6th, and 8th cell (in a 3x3-cell grid) to form a border of any size with just those assets. Stretching just a plain image would result in distortion of the corners, so I'd like to stretch those even numbered cells as needed and tack on the corners so there is no distortion. I'd seen this done before so thought it might be a standard thing and have a standard naming to it other than what I called it.
Anyhow, I was advised that adding 8 UIImageViews to a container would not be as efficient as drawing the UIImages on the fly in drawRect so took that approach using CGContextDrawImage() after applying the necessary transformations to the context to translate and scale the Y. Because this function draws from the bottom left corner of an image but onto a top-left origined UIView, the image is upside down without the Y axis invert. I noticed the suggestion to use UIImage functions like drawAtPoint works as well and similarly but for the invert since UIImage draws in the same orientation as UIViews. I will continue my implementation with the former and see how it goes, but one other question.
Would someone happen to know which of these approaches is more efficeint, faster, etc?
I'm not sure I follow, but here's my best shot at an answer...
Using drawRect: or adding individual UIImageViews to a parent view is entirely up to you. UIImageView gives you a bit of encapsulated functionality for free, but otherwise they are the same as far as appearances go.
If you do want to go the drawRect route, you just need to use UIImage's drawAtPoint: method. Do the math for where you want it to be, and draw it. You can calculate your points based on the parent view's dimensions.
As far as scaling, it's impossible to resize these images without scaling them, so I'd plan ahead and make your originals as large or larger than you ever expect to display them.
Hope that helps a little?
Cheers
If you want a border on a dialog box, assuming the box is a UIView (or subclass), then set the layer's border properties and let the system draw the border for you.
#import <QuartzCore/QuartzCore.h>
// ...
view.layer.borderWidth = 2;
view.layer.borderColor = [UIColor whiteColor].CGColor;
view.layer.cornerRadius = 0; // 0=square corners, >0 for rounded

iPhone: CALayer + rotate in 3D + antialias?

An iPhone SDK question: I'm drawing a UIImageView on the screen. I've rotated it in 3D and provided a bit of perspective, so the image looks like it's pointing into the screen at an angle. That all works fine. Now the problem is the edges of the resulting picture don't seem to be antialiased at all. Anybody know how to make it so?
Essentially, I'm implementing my own version of CoverFlow (yeah yeah, design patent blah blah) using quartz 3d transformations to do everything. It works fine, except that each cover isn't antialiased, and Apples version is.
I've tried messing around with the edgeAntialisingMask of the CALayer, but that didn't help - the defaults are that every edge should be antialiased...
thanks!
If you rotate only one image, than one trick will resolve the problem. Try to set
layer.shadowOpacity = 0.01;
After that picture will look smoother after 3D Rotation
The Gloomcore answer give a really neat result.
however this sometime make things really LAGGY !
Adding rasterization help a little bit:
.layer.shadowOpacity = 0.01;
.layer.shouldRasterize = YES;
I know the question/answer is old, but hey i just found it.
You could try adding some transparent pixels around the edge of the image, either by putting the UIImageView in a slightly larger empty view that you apply rotation to, or by changing the source images.
I had a similar issue that was solved by only setting shouldRasterize = YES, however because I was re-using my views (and layers), the shouldRasterize = YES killed the performance.
Fortunately I found a solution by turning shouldRasterize = NO at the right time to restore performance in my app's case.
I posted a solution here: Antialiasing edges of UIView after transformation using CALayer's transform
You can try this
Method: Using layer.shouldRasterize
Create a superlayer/superview which is 1 pixel bigger in all 4 directions
Do the transform on the superlayer/superview
Enable layer.shouldRasterize on the original layer/view
Method: Drawing to a UIImage
Draw your content to a UIImage
Make sure that you have a transparent border of 1 pixel around the content
Display the image
Reference: http://darknoon.com/2012/05/18/the-transparent-border-trick/

How to animate a polygon mask with performance?

I'm having a performance issue.
I've created an UIView and overwrited it's drawRect function. At this function, I was drawing an image (big one), and over that, an white square at the entire screen with a polygon inside it, with CGContextEOFillPath. The result is an white screen with portion of the image (defined by the polygon) displayed.
After that, I created a function to animate the transition of that polygon to another one. Besides the polygon animation, the image should also be scaled and moved to fix the diplayed at the screen. I did that with an NSTimer. The animation of the polygon consists in calculating the distance between each vertex and moving then to a position according to elapsedTime. It worked just fine at the simulator, but got really stucked at device.
Reading about performance, here at stackoverflow, I found the alternative to use beginAnimations and commitAnimations. I'm changing everything to use that approach with the image. But what can I do with the polygon. The polygon is drawn with CGContextMoveToPoint and CGContextAddLineToPoint, so I believe it can't be animated with beginAnimations. An I correct? Is there a better approach to do that?
The desired result is something like this comic reader app: http://www.comixology.com/iphoneapp (click on guided tour. at the middle of the video they show the "automatic masking" feature)
My suggestion would be to use a CAShapeLayer overlaid on your main image view, with the CAShapeLayer being the size of the view you want to mask and having a polygon path for a hole in the center of it. CAShapeLayers let you animate from one CGPathRef to another smoothly, as long as the two paths have the same number of control points. You will need to use a CABasicAnimation here to do that animating, rather than a UIView begin / commitAnimations block, but it's not too difficult.
Joe Ricioppo has a nice example of animating CAShapeLayer paths in his post here.
With Core Animation you can animate "animatable" (sic) properties. Apple's documentation enumerates animatable properties in Mac OS X:
http://url.akosma.com/55
In the case of the iPhone, the UIView documentation explicitly says "animatable" when a given property is, hum, animatable. The most powerful of these are (IMHO) UIView's "transform" property, which takes CGAffineTransform structs as inputs, or CALayer's "transform" property (which takes CATransform3D structs). Both are animatable and give you tremendous power to create any kind of transition you want.
Now, in your case, indeed, you can't animate the polygon in an "easy" way. My bet would be in your case to try to map CGAffineTransforms that fit your needs (scale, translation) and apply that to a fixed view, non-animated, created using your Quartz code.
I hope I'm clear enough :)

How to implement slurp effect on iPhone?

The iPhone has a private list of effects that Apple uses, such as "genieEffect" and "slurpEffect". I'm wondering how one would go about implementing the slurp effect (this is when you trash a mail message or a note).
I understand how to use Core Animation, but I'm not sure exactly what parts of it they're using to get that animation.
This post talks about using the private API for the effect:
link text
It seems to be a complex combination of 2D and 3D transformations. :-\ You'd have to really delve into CoreAnimation to simulate this effect.
I would do it with an affine transformation applied to the view's layer. Linear algebra is not my strong point ;) so I can't specify the exact transformation but my guess would be something like this for the animation:
Set the alpha to fade to 0.0 or
something close to 0
Apply a transform to squish the two bottom corners close to the center
Scale down the view to very small
move the layer's center down to the bottom of the screen (or wherever you want it to genie to.
That's more or less how I think it would work. You might have to animate these things at different times, or all in one block, I'm not quite sure.
Have a look at documentation for CALayer, CABasicAnimation, and CGAffineTransform.