how to apply an imageview frame with the inclined coordinates - iphone

hi all upto now i know making rectangle with the CGrectmake and this rect(frame) i am using as imageview frame like UIImageView *someImage=[[uiimageview alloc]initwithframe:someRect]; now i can add an image with the frame of someRect. my problem here is when the coordinates like
(rectangleFirstx-coordinate,tectangleFirstY-cordinate)=(10,10)
(rectangleLastx-cordinate,rectangleLasty-cordinate)=(17,7) this, how can i give frame to the uiimageview....This is like a inclined rectangle..can any one suggest me how to apply frame through the ios library for these type of coordinates..Thanks in advance..

Your example isn't very clear because a rectangle with opposite corners at (10,10) and (10,7) can be in any one of a myriad of different orientations, including one perfectly aligned along the x and y axis.
What you can certainly do is create a UIImageView of the desired size and location and then rotate it by using one of many techniques, including animation methods.
[UIImageView animateWithDuration:0.1 animations:^
{
your_UIImageView_here.transform = CGAffineTransformMakeRotation((M_PI/180.0) * degrees);
}];
You can hide the UIImageView until the rotation is done and then show it.
If your question is about how to use the coordinates you provided to arrive at an angle I'd suggest that more data is needed because it is impossible to pick one of the billions of possible rectangles with corners at those two points without more information. Once you have more data then it is pretty basic trigonometry to figure out the angle to feed into the rotation.

Related

How to change length of line and rotate it dynamically?

I am trying to draw a simple straight line. For this, I am filling an UIImageView with some color with given width as, say 2 pixel and some length. Now user is provided with two UISliders out of which one is used to stretch the line and another slider to rotate. I use myImageView.frame to change the height and CGAffineTransform to rotate. It works fine until I change the rotation angle using slider. But once I rotate the imageview, The slider to stretch doesn't work properly.
I have searched and found that frames won't work after rotating using CGAffineTranfor.
Alternately bounds should work but that didn't work too.
Seeking help. Any brief code will help me.
Thanks in advance.
Give transformed bounds every time you apply a transform. This should work:
CGRect transformedBounds = CGRectApplyAffineTransform(myView.bounds, myView.transform);

I used CGPath to make a picture with 4 CALayers, how can I zoom in and out?

I used CGPath to make a picture with 4 CALayers, how can I zoom in and out?
The picture contained a four different circles, a rectangle, and a more complicated shape.However, I want to make it zoom in and out like UIRefreshControl.
It's unrealistic to control every shape at the same time to make it look like the original.
If you need it:
in your drawInRect: method you can add CGContextScaleCTM (yourContext,scaleX,scaleY); when scaleX and scaleY are CGFloat. Experiment with it. For example you can set scale with a UISlider.

UIImageView image blur after rotate it

I rotate a UIImageView using the following code:
[imageView setTransform:CGAffineTransformMakeRotation(-0.10)];
but it looks blurry after the rotation, like this.
What's the problem?
It could be that the resulting frame isn't aligned on an even integer. When you are drawing on a half-pixel boundary, some of the drawing routines are going to make things look blurry.
If you see any non-integer values, use one of the floor() functions to modify the resulting frame in order to snap it to a boundary.

Changing UIVIEW's transformation/rotation/scale WITHOUT animation

I need to change the size of my images according to their distance from the center of the screen. If an image is closer to the middle, it should be given a scale of 1, and the further it is from the center, the nearer it's scale is to zero by some function.
Since the user is panning the screen, I need a way to change the images (UIViews) scale, but since this is not a very classic animation where I know a how to define an animation sequence exactly - mostly because of timing issues (due to system performance, I don't know how long the animation will last), I am going to need to simply change the scale in one step (no timed animations).
This way every frame the functiion gets called when panning, all images should update easily.
Is there a way to do that ?
You could directly apply a CGAffineTransform to your UIImageView. i,e:
CGAffineTransform trans = CGAffineTransformMakeScale(1.0,1.0);
imageView.transform = trans;
Of course you can change your values, and or use other CGAffineTransform's, this should get you on your way though.
Hope it helps !

Image stretching

I want Stretch a image. For that i use sprite. I want stretch sprite & this stretching is may be Circular or curve animation. I don't understand what methode used for that. Can anyone help me?
Since you tagged your question with cocos2d I guess you'll be using that. It's really basic to strech an image
Sprite *mySprite = [Sprite spriteWithFile:#"mysprite.png"];
mySprite.position = ccp(100, 100);
mySprite.scale = 2.0;
[self addChild:mySprite];
If you want to animate it you can use the cocos2d actions or just create your own animation. The example below does a linear animation to 3x original sprite size in 1 second:
id action1 = [ScaleTo actionWithDuration:1.0 scale:3.0];
[mySprite runAction: action1];
For manipulating views and images in general in ways such as streching you can read up on transforms provided by the sdk, you can learn about 2D transforms here http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_affine/dq_affine.html and you can extend that further to 3D by manipulating the layers transforms instead of the views transforms. Youll be able to do things such as scaling and rotating and you can define your own transforms as well. This example project http://developer.apple.com/iphone/library/samplecode/MoveMe/ is a good reference to get started with transforms and animating them.