How do I get the position and size of an image after applying a transform?
Currently I'm developing a game in which I've an imageView which I'm scaling little by little & rotating at the end. I want to obtain the size of image & its coordinates ar the end of scaling which I need for 3D rotating the imageView which I need to redraw the image & apply rotation to it. I'm using
if(ravanImage.center.y>=300&&ravanImage.center.y<=370)
{
ravanImage.transform = CGAffineTransformScale(ravanImage.transform, 0.98, 0.98);
}
if(ravanImage.center.y>=2开发者_StackOverflow社区30&&ravanImage.center.y<=299)
{
ravanImage.transform = CGAffineTransformScale(ravanImage.transform, 0.98, 0.98);
}
if(ravanImage.center.y>=150&&ravanImage.center.y<=229)
{
ravanImage.transform = CGAffineTransformScale(ravanImage.transform, 0.98, 0.98);
}
for scaling image during three intervals of coordinates. Each time it enters if loop, it reduces in size. This animation basically is for an arrow which I want to show as moving away from us inside the screen. I want to obtain the last statistics of the image after last scale.
Can anybody please help me?
You can do this by extracting the final transform and applying that transform to your original view values:
CGPoint ravanImageOrigin = ravanImage.frame.origin;
CGSize ravanImageSize = ravanImage.bounds.size;
// Transforming code here
CGAffineTransform currentTransform = ravanImage.transform;
CGPoint newImageOrigin = CGPointApplyAffineTransform(ravanImageOrigin, currentTransform);
CGSize newImageSize = CGSizeApplyAffineTransform(ravanImageSize, currentTransform);
One thing to watch out for here is in dealing with the position. Transforms for a view are applied about its center point, by default, so the above may not give you the correct ending coordinate for the origin of the view. You may need to subtract values so that the origin is in coordinates relative to the center of the view, then add the center view coordinate back after you've applied the transform.
精彩评论