来自UIImage参考,
尺寸
图像的尺寸,考虑方向.(只读)
@property(nonatomic, readonly) CGSize size
Run Code Online (Sandbox Code Playgroud)
讨论
在iOS 4.0及更高版本中,此值反映图像的逻辑大小,并以磅为单位进行测量.在iOS 3.x及更早版本中,此值始终反映以像素为单位测量的图像尺寸.
像素和点之间有什么区别?
我正在做一个UIView高度的简单动画,以便它显示出来.
默认情况下,它似乎从上到下显示,我希望它从下到上显示.
我把UIView固定在屏幕的底部.
我确定它很简单,我很遗憾.....任何提示?
谢谢
我想在左上角旋转图像,而不是中心.根据文档,我将anchorPoint属性设置为[0,1].视图在我的示例中旋转50°,但在它开始动画之前,视图会跳转到屏幕上的另一个点.
self.shakeTag.layer.anchorPoint = CGPointMake(0.0f, 1.0f);
[UIView beginAnimations:@"rotate" context:nil];
[self.shakeTag.layer setTransform:
CATransform3DRotate(CATransform3DIdentity,
radians(50.0), 0.0f, 0.0f, 1.0f)];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
radians() 定义如下:
static inline double radians (double degrees) {return degrees * M_PI/180;}
Run Code Online (Sandbox Code Playgroud)
当我使用4倍大小并且具有大量透明像素的图像时,我可以在默认锚点[0.5,0.5]处旋转它,但我不想浪费空间用于不可见像素.任何想法如何防止图层在旋转发生之前跳跃?
我正在创建一个CAShapeLayer.我正在为它添加旋转动画.不知何故转化结果很奇怪.子图层随着旋转一起移动.我需要它在固定的中心/位置(锚)并旋转.我知道它弄乱了几何变换,但我无法做到正确.
我试过设置anchorpoint.我也跟着这篇文章
这是代码:
UIBezierPath *circle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(75, 125)
radius:50
startAngle:0
endAngle:1.8 * M_PI
clockwise:YES];
CAShapeLayer *circleLayer = [CAShapeLayer layer];
[circleLayer setFrame:CGRectMake(200 - 50, 300 - 50, 100, 100)];
circleLayer.path = circle.CGPath;
circleLayer.strokeColor = [UIColor orangeColor].CGColor;
[circleLayer setFillColor:[UIColor clearColor].CGColor];
circleLayer.lineWidth = 3.0;
if ([circleLayer animationForKey:@"SpinAnimation"] == nil) {
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat: 2 * M_PI];
animation.duration = 10.0f;
animation.repeatCount = INFINITY;
animation.removedOnCompletion = NO;
[circleLayer addAnimation:animation forKey:@"SpinAnimation"];
}
[self.view.layer addSublayer:circleLayer];
Run Code Online (Sandbox Code Playgroud) 什么是CALayer(如layerUIView上的属性所示)以及我们在哪里使用这样的类?
我有一个UIView子类,我希望能够在它的superview中移动.当用户在外面某处触摸UIView self.center但在self.bounds其中"跳跃"时,因为我添加新位置self.center以实现实际移动.为了避免这种行为,我试图设置一个锚点,让用户抓住并拖动视图在其范围内的任何位置.
我的问题是,当我计算新的锚点(如下面的代码所示)没有任何反应时,视图根本不会改变位置.另一方面,如果我将锚点设置为预先计算的点,我可以移动视图(但当然它会"跳转"到预先计算的点).为什么这不能按预期工作?
谢谢.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// Only support single touches, anyObject retrieves only one touch
UITouch *touch = [touches anyObject];
CGPoint locationInView = [touch locationInView:self];
// New location is somewhere within the superview
CGPoint locationInSuperview = [touch locationInView:self.superview];
// Set an anchorpoint that acts as starting point for the move
// Doesn't work!
self.layer.anchorPoint = CGPointMake(locationInView.x / self.bounds.size.width, locationInView.y / self.bounds.size.height);
// Does work!
self.layer.anchorPoint = CGPointMake(0.01, 0.0181818);
// Move …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.对于锚点,是否可以在父视图上设置位置?目前我正在相对于当前视图任意设置它.
提前感谢任何指针.
在动画之前

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

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

视频已添加:示例视频
我试图改变我的Sprite锚点,以便我可以旋转0.0f,0.0f锚点.起初我的对象是默认锚点(0.5f,0.5f)处的旋转.但是后来我需要它在0.0,0.0 AnchorPoint上旋转.
问题是我不能改变锚点并相应地改变位置,因此它保持在同一位置,没有对象看起来快速移动并重新定位到其原始点.
有没有办法可以立刻设置锚点和我的精灵的位置,而根本不移动它?谢谢.
-Oscar
我有一个UIPanGestureRecognizer附加到我的iOS应用程序中的视图.我从平底锅处理程序的Touches示例应用程序中复制了代码.手势开始时,我的代码:
将锚点和中心更改为围绕用户的手指,如下所示:
CGPoint locationInView = [gestureRecognizer locationInView:target];
CGPoint locationInSuperview = [gestureRecognizer locationInView:target.superview];
target.layer.anchorPoint = CGPointMake(
locationInView.x / target.bounds.size.width,
locationInView.y / target.bounds.size.height
);
target.center = locationInSuperview;
Run Code Online (Sandbox Code Playgroud)随着手势的进行,平移处理器不断地改变中心以跟踪手指的移动.到现在为止还挺好.
当用户放手时,我希望视图动画回到其原始起点.执行此操作的代码如下所示:
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationCurveEaseOut animations:^{
target.center = originalCenter;
target.layer.anchorPoint = originalAnchorPoint;
}];
Run Code Online (Sandbox Code Playgroud)
这确实使视图回归到其原始起点.但是,在动画开始之前,视图会跳转到UI中的其他位置.IOW,放手,它跳跃,然后它动画回到它所属的位置.
我想也许我需要设置锚点并在动画外部居中,也许将中心设置为超级视图中的位置,就像手势开始时一样,但这似乎没有区别.
我在这里错过了什么?当用户放手时,如何防止跳转?
iphone ×5
ios ×4
objective-c ×4
uiview ×3
animation ×2
cocoa-touch ×2
caanimation ×1
calayer ×1
cglayer ×1
cocoa ×1
ipad ×1
macos ×1
pixel ×1