2012年11月3日 星期六

UIView的Animation(十ㄧ)

在UIView的矩陣轉換後結果的評估


如果在正式轉換前,我們需要評估圖區轉換後的位置,並適當地加入控制程式在轉換後的位置,就必須應用下面三個Function,分別可以得到點/位置/大小。
不另外做試驗程式,僅作資料整理。


Apple 原始資料
https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGAffineTransform/Reference/reference.html


CGPointApplyAffineTransform

Returns the point resulting from an affine transformation of an existing point.
CGPoint CGPointApplyAffineTransform (
   CGPoint point,
   CGAffineTransform t
); 
 

CGRectApplyAffineTransform

Applies an affine transform to a rectangle.
CGRect CGRectApplyAffineTransform ( CGRect rect, CGAffineTransform t );

CGSizeApplyAffineTransform

Returns the height and width resulting from a transformation of an existing height and width.
CGSize CGSizeApplyAffineTransform (
   CGSize size,
   CGAffineTransform t
);

 

example1

CGAffineTransform translateTransform = CGAffineTransformMakeTransation(point.x, point.y);

CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(angle);

CGAffineTransform customTransform = CGAffineTransformConcat(CGAffineTransformConcat(
CGAffineTransformInvert(translateTransform), rotateTransform), translateTransform);

newPoint = CGPointApplyAffineTransform(initialPoint, customTransform);



example2

CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
CGAffineTransform zt = CGAffineTransformScale(CGAffineTransformIdentity, factor, factor); senderView.frame = CGRectApplyAffineTransform(initialFrame, zt);




example3

CGRect imgRect = CGRectMake(0, 0, width, height);
CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform);


example4


CGSize imageViewSize = previewImage.size; 
CGSize imageSize = previewImage.image.size; 
// Find the scaling required for the image
 to fit the image view (as for aspect fill). 
CGFloat imageWidthScale = fabsf(imageViewSize.width / imageSize.width); 
CGFloat imageHeightScale = fabsf(imageViewSize.height / imageSize.height); 
CGFloat imageScale = (imageWidthScale > imageHeightScale) ? 
imageWidthScale : imageHeightScale; 
// Determine the new image size, after scaling. 
CGSize scaledImageSize = CGSizeApplyAffineTransform(imageSize, CGAffineTransformMakeScale(imageScale, imageScale));




example5
 
CGSize oldImageSize = imageView.bounds.size;
// Transforming code here
CGAffineTransform currentTransform = imageView.transform;
CGSize newImageSize = CGSizeApplyAffineTransform(oldImageSize, currentTransform);




沒有留言: