我想改变anchorPoint,但保持视图在同一个地方.我试过NSLog-ing分词self.layer.position和self.center他们都保持不变,无论更改anchorPoint的.然而我的观点却在变化
关于如何做到这一点的任何提示?
self.layer.anchorPoint = CGPointMake(0.5, 0.5);
NSLog(@"center point: %f %f", self.layer.position.x, self.layer.position.y);
self.layer.anchorPoint = CGPointMake(1, 1);
NSLog(@"center point: %f %f", self.layer.position.x, self.layer.position.y);
Run Code Online (Sandbox Code Playgroud)
输出是:
2009-12-27 20:43:24.161 Type[11289:207] center point: 272.500000 242.500000
2009-12-27 20:43:24.162 Type[11289:207] center point: 272.500000 242.500000
Run Code Online (Sandbox Code Playgroud) 我需要将灰色视图内的红色视图放大到滚动视图内的给定红色边界(在这种情况下,滚动视图边框取决于给定的宽度/高度比),同时保持视图的可见尺寸不变。他们还应该始终触摸绿色边框。
我尝试在此视图上使用缩放变换来实现此目的,以便在放大滚动视图时,我使用公式1 / zoomScale并更改其锚点来缩小此视图,以使其保持绿色边框。
问题是在进行所有这些操作后,我不知道如何为红色视图计算目标边界rect,因此我可以使用适当的滚动到它zoomScale。
编辑
灰度视图可能会缩小滚动视图边界(请参见上一张图片),主要是要在滚动视图边界内放入由红色视图包围的绿色矩形(您可能会认为它们是绿色区域的负插图),因此我们应该实际计算考虑到绿色矩形的起始和结束尺寸,应将红色视图“固定”到该矩形。
基本方法
- (void)adjustScrollPositionAndZoomToFrame:(CGRect)frame
{
CGFloat viewWidth = frame.size.width;
CGFloat viewHeight = frame.size.height;
CGFloat scrollViewWidth = self.scrollView.frame.size.width;
CGFloat scrollViewHeight = self.scrollView.frame.size.height;
CGSize newSize = [self scaleSize:frame.size toHeight:scrollViewHeight];
if (newSize.width > scrollViewWidth) {
newSize = [self scaleSize:frame.size toWidth:scrollViewWidth];
}
CGFloat scaleFactor = newSize.height == scrollViewHeight
? scrollViewHeight / viewHeight
: scrollViewWidth / viewWidth;
[self scrollRect:frame toCenterInScrollView:self.scrollView animated:NO];
self.scrollView.zoomScale = scaleFactor;
}
Run Code Online (Sandbox Code Playgroud)
缩放比例
- (void)handleZoom:(CGFloat)zoom
{
NSArray *anchorPoints = …Run Code Online (Sandbox Code Playgroud) 所以,我正在尝试创建一个平铺翻转效果,就像在Windows Phone 7上一样.
到目前为止,我有以下代码,但我有几个问题.
CALayer *layer = self.theRedSquare.layer;
CATransform3D initialTransform = self.theRedSquare.layer.transform;
initialTransform.m34 = 1.0 / -1000;
[UIView beginAnimations:@"Scale" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
layer.transform = initialTransform;
layer.anchorPoint = CGPointMake(-0.3, 0.5);
CATransform3D rotationAndPerspectiveTransform = self.theRedSquare.layer.transform;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI , 0 , -self.theRedSquare.bounds.size.height/2, 0);
layer.transform = rotationAndPerspectiveTransform;
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
为什么我的红色方块(一个简单的UI视图)在动画开始时转换为右边?
2.对于锚点,是否可以在父视图上设置位置?目前我正在相对于当前视图任意设置它.
提前感谢任何指针.
在动画之前

在动画期间(注意方块向右移动)

动画后(注意方块向右移动)

视频已添加:示例视频
iphone ×2
algorithm ×1
cocoa ×1
cocoa-touch ×1
ios ×1
ipad ×1
objective-c ×1
uiscrollview ×1
uiview ×1