First post here, great site!
Basically, Im trying to rotate a UIImageView based on two points. Imagine the two points form a line going across the screen. I need the angle of the UIImageView to match the angle of that line...
Heres a diagram of what Im trying to say as its quite hard with words:
http://i40.tinypic.com/t5k2yr.png
Thanks for your time!
Would this work?
imageView.transform = CGAffineTransformMakeRotation(atan2(y2-y1,x2-x1));
Related
I am working on an iPad app, and one of the features that has been requested is the ability to make measurements of an image. With the knowledge that the iPad screen has a 132ppi resolution, it seems as though it will be quite simple to implement this.
But how can I draw a straight line on the iPad? Is there a library that is best? Is core animation, open gl, or quartz what I need? I don't have any experience drawing anything, so if someone can just be like "do this", I'll go figure out how to do it. I want to make it so the user can't draw anything but a straight line, and then when they are done, I need to know how many pixels long the line is.
Please help. Thanks
EDIT I forgot to make this clear, I would like to be able to make it so the line is drawn as the user goes. So they put the finger down, and then maybe a little dot appears, then as they drag, the line gets linger, and when they stop, the line is done.
Please see this answer:
How do I draw a line on the iPhone?
Also, to get the length, implement touchesBegan and touchesEnded, record both CGPoints and calculate the delta.
The distance formula
In code:
CGFloat dx = point2.x - point1.x;
CGFloat dy = point2.y - point1.y;
CGFloat distance = sqrt(dx*dx + dy*dy);
I want to create a 360 degree turntable showing lots of pictures (12, 24 or 36) by controlling that rotation with touch events (like that example but coded for an iOS app natively).
The simplest idea depending on the touch position is to load that specific uiimage.
Any ideas what's the best practice for that? Is there a chance to create that image-turntable with the help of coreanimation faster? Any other hints on that? Any other projects known where I can get some help on that?
Thanks for your time and hints in the right direction.
Here's another example for an ipad-app from the "audi a8".
From the first example it becomes obvious that the objects have actually been photographed for each angle of rotation. This is the really tricky part. You will need a tripod and a camera with remote control, and if possible also a rotational platter to keep angles consistent.
Implementation is relatively straightforward. As you guessed, you just track the touch positions and, depending on delta to the last touch position, show the appropriate image.
well, you can just use the HTML/CSS/JS used in the same example... just load that in an UIWebView in your app and load your site embedded as a resource...
Subclass UIImageView, load array of your frames, handle tap movement over the screen y-axis and change active image accordingly. Don't forget to loop your images. :)
I have an array of jpgs (7) that I would like to print. All the images are the same size, 900x1382, and I would like to print them two to a page by rotating them 90 degrees and printing them top/bottom on a letter sized piece of paper.
It sounds like I need to create a printFormatter but that's where I am getting stuck. I have read through Apple's Drawing and Printing Guide probably 10 times and I cannot figure how to do what I want to do.
Can someone help me out or at least point me in the direction of a good tutorial?
- (void)drawPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)printableRect
{
// You can draw images in the specified rect.
}
Try to subclass UIPageRenderer, then override the above function. You can draw the images in specified rect. I think you have to check the Apple's PrintPhoto sample code, and custom drawing from your old guide. Check it and add comments about this. thanks :)
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/
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.