标签: core-animation

我该怎么在iPhone上做多个动画?

我想为一个游戏制作动画片,我想让这些片段向不同的方向移动,这样我现在的动画整个视图的方法将不再适用.

我想知道一次动画多个项目的最佳做法是什么.(注意我在2d渲染所以我目前对3d解决方案不感兴趣.)

谢谢!

iphone 2d core-animation calayer quartz-graphics

1
推荐指数
1
解决办法
4462
查看次数

旋转始终从原始位置开始

我正在尝试实现轮式功能.我计算视图的中心点,并找到在touchesMoved:方法中移动时创建的角度.对于第一步,它旋转了一定程度.但是对于下一步移动它会回到视图的原始位置然后旋转.实际上我希望从前一轮的终点开始旋转.什么事都缺了?有任何帮助

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    float a, b,c;   

    UITouch *aTouch = [touches anyObject];
    if ([aTouch view] == dialView) {

        CGPoint loc = [aTouch locationInView:dialView];
        CGPoint prevloc = [aTouch previousLocationInView:dialView];

        c = [self GetSides:prevloc point2:loc]; 
        a = [self GetSides:loc point2:cntrePoint];
        b = [self GetSides:prevloc point2:cntrePoint];

        float angle = acos((a*a+b*b-c*c)/(2*a*b));// Calculating angle created on moving

        CABasicAnimation  *rotate ;
        rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        rotate.fromValue = [NSNumber numberWithFloat:0];
        rotate.toValue = [NSNumber numberWithFloat:((angle*M_PI)/180)];
        rotate.autoreverses = NO;
        rotate.fillMode = kCAFillModeForwards;
        rotate.duration = 1;
        rotate.repeatCount …
Run Code Online (Sandbox Code Playgroud)

iphone core-animation

1
推荐指数
1
解决办法
3423
查看次数

像Tweetie一样滑动显示菜单

我一直在研究一个新的应用程序,并且真的希望实现一次滑动以在我的应用程序中显示更多选项菜单.我进行了搜索和搜索,但似乎没有其他人成功地使其工作(除了Loren).我要做的是滑动单元格,同时使用CABasicAnimation将其推送到x:320,并在此下面添加一个子视图,其中包含按钮等.我正在使用willBeginEditing来检测滑动以避免子类化.这是代码:

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {

 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

 CABasicAnimation *theAnimation;          

 theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];

 theAnimation.duration=0.0;

 theAnimation.repeatCount=0;

 theAnimation.autoreverses=NO;

 theAnimation.removedOnCompletion = NO;

 theAnimation.fillMode = kCAFillModeForwards;

 theAnimation.fromValue=[NSNumber numberWithFloat:0];

 theAnimation.toValue=[NSNumber numberWithFloat:+320];

 [cell.layer addAnimation:theAnimation forKey:@"animateLayer"];

 CGRect frame = CGRectMake(0, 59 * indexPath.row, 320, 59);

 UIView *menu = [[[UIView alloc] initWithFrame:frame] autorelease];


 NSString *path = [NSString stringWithFormat:@"%@%@",

                       [[NSBundle mainBundle] resourcePath],

                       @"/flick.wav"];



 SystemSoundID soundID;

 NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

 AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);

 AudioServicesPlaySystemSound(soundID);

 self.menu.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"dots.png"]];

 [self.view addSubview:menu];

 [self.view sendSubviewToBack:menu];

 }



- (void)animationDidStop:(NSString*)animationID …
Run Code Online (Sandbox Code Playgroud)

iphone core-animation uitableview cabasicanimation

1
推荐指数
1
解决办法
5777
查看次数

在没有动画的情况下向CALayer添加子图层?

如何在没有动画的情况下向CALayer添加子图层?通常当你添加一个" 淡入 "时,当你删除一个它"淡出".

如何抑制动画?

core-animation objective-c calayer

1
推荐指数
1
解决办法
2389
查看次数

CATransaction(仍然)不动画

我有一个与此非常相似的问题:

CATransaction不动画

我只是想尝试使用CATransaction为视图层设置动画.我的问题是变换立即应用于视图.

我尝试使用performSelector执行动画:withObject:afterDelay:没有成功.

这是我的代码:

- (void)viewDidLoad {
    [super viewDidLoad];

 view = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] autorelease];
 view.backgroundColor = [UIColor blackColor];
 [self.view addSubview:view];

 [self performSelector:@selector(animateView) withObject:nil afterDelay:0.1];
}

-(void) animateView {
 [CATransaction begin];
 [CATransaction setValue:[NSNumber numberWithFloat:3.0f] forKey:kCATransactionAnimationDuration];
    CALayer *layer = view.layer;
    layer.position = CGPointMake(20, 
         300);
    CATransform3D transform = CATransform3DMakeScale(2.0f, 2.0f, 1.0f);
    transform = CATransform3DRotate(transform, acos(-1.0f)*1.5f, 1.5f, 1.5f, 1.5f);
    layer.transform = transform;
    [CATransaction commit];
}
Run Code Online (Sandbox Code Playgroud)

有谁知道出了什么问题?

谢谢,文森特.

iphone core-animation

1
推荐指数
1
解决办法
2532
查看次数

对于实时游戏,我应该经常使用核心动画还是重绘图像?

假设我必须根据用户输入在屏幕上移动图像....

我是不是该?

  • 定期使用核心动画以小块为动画制作动画.

要么

  • 经常在不同位置重绘图像.

如果没有明确的答案,使用每种方法有什么好处?

iphone core-animation objective-c

1
推荐指数
1
解决办法
294
查看次数

从CALayers绘制图像

我正在构建某种审查应用程序.到目前为止,我已经完成了用我的iPhone拍摄的图像像素化.

但我想最终实现这样的图像:http://images-mediawiki-sites.thefullwiki.org/11/4/8/8/8328511755287292.jpg

所以我的想法是完全像素化我的图像,然后在它上面添加一个蒙版,以达到预期的效果.因此,就层次而言,它就像:originalImage + maskedPixelatedVersionOfImage ..我正在考虑在触摸图像时为蒙版设置动画,以将蒙版缩放到所需的大小.手指放在图像上的时间越长,面具就越大......

经过一番搜索,我想这可以使用CALayers和CAAnimation来完成.但是,我如何将这些图层合成到我可以保存在iphone上的photoalbum中的图像?

我在这里采取正确的方法吗?

编辑:

好吧,我觉得Ole的解决方案是正确的,虽然我仍然没有得到我想要的东西:我使用的代码是:

    CALayer *maskLayer = [CALayer layer];
    CALayer *mosaicLayer = [CALayer layer];

    // Mask image ends with 0.15 opacity on both sides. Set the background color of the layer
    // to the same value so the layer can extend the mask image.
    mosaicLayer.contents = (id)[img CGImage];
    mosaicLayer.frame = CGRectMake(0,0, img.size.width, img.size.height);
    UIImage *maskImg = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"mask" ofType:@"png"]];
    maskLayer.contents = (id)[maskImg CGImage];
    maskLayer.frame = CGRectMake(100,150, maskImg.size.width, maskImg.size.height);

    mosaicLayer.mask …
Run Code Online (Sandbox Code Playgroud)

iphone core-animation core-graphics objective-c quartz-graphics

1
推荐指数
1
解决办法
7960
查看次数

CALayer没有在UIImageView中显示

我有一个已设置图像的UIImageView,并尝试将CALayer添加为子视图.它工作(子层计数从0上升到1)但屏幕上没有任何反应.即使我尝试将图层背景设置为黑色或将隐藏设置为"否".

 CALayer*layer=[[CALayer alloc]initWithLayer:anotherUIImageView.layer];

[myUIImageVIew.layer addSublayer:layer];

[[myUIImageView.layer.sublayers objectAtIndex:0] setHidden:NO];
[[myUIImageView.layer.sublayers objectAtIndex:0] setBackgroundColor:[UIColor blackColor]];
Run Code Online (Sandbox Code Playgroud)

任何的想法?

core-animation objective-c uiimageview ios

1
推荐指数
1
解决办法
2679
查看次数

iOS 5的Messages.app键盘附件查看行为

Messages.app截图

在iOS 5的Messages.app显示中,任何人都可以解释如何最好地模仿"附件视图"(在倒置逗号中,因为我实际上并不认为它是附件视图)的行为,因为我想要一个给人留下深刻印象的视图它固定在键盘顶部,但在键盘解除后仍保留在屏幕上.

iphone core-animation objective-c uiview ios

1
推荐指数
1
解决办法
1482
查看次数

在iOS上,为什么更改CALayer的框架不会导致动画?

我有一些iOS示例代码,如果我点击主视图并点击处理程序更改CALayer对象的frame属性,图层对象将设置其位置和大小的动画.

但是,如果我把动画里面ViewControllerviewDidLoad:

UIImage *shipImage = [UIImage imageNamed:@"SpaceShip1.png"];
ship1 = [[CALayer alloc] init];

ship1.contents = (id) [shipImage CGImage];
ship1.frame = CGRectMake(50, 50, 100, 100);

[self.view.layer addSublayer:ship1];

ship1.frame = CGRectMake(0, 0, 300, 200);
Run Code Online (Sandbox Code Playgroud)

那么动画就不会发生.它只会使用(0, 0, 300, 200)没有动画的.为什么这样以及如何使其发挥作用?

iphone core-animation ios

1
推荐指数
1
解决办法
4838
查看次数