Tag: 核心animation

在启动时使用一组图像添加animation

我是新的iPhone应用程序开发,我试图添加一个图像,我的应用程序的开始。 我创build了一个图像数组,当迭代时应该创build一个animation。 -(void)viewDidLoad { animation = [[UIImageView alloc] init]; animation.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"panda1.png"], [UIImage imageNamed:@"panda2.png"], [UIImage imageNamed:@"panda3.png"], nil]; animation.animationRepeatCount = 2; animation.animationDuration = 2; [animation startAnimating]; [self.view addSubview:animation]; [animation release]; //for loading the webpage at start up NSString *urlAddress = @"http://projects.seng.uvic.ca/fatpanda/m/most_recent.php"; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; //load the […]

iPhone的方向 – 如何找出哪个方向是?

我试图在屏幕上总是面向“向上”绘制2D图像。 如果用户正在旋转他们的手机,我想确保我的2D对象不随设备旋转; 它应该总是“站立”。 我想补偿用户向左或向右倾斜,而不是倾斜或向自己倾斜。 我正在使用CoreMotion从设备中获取音调,滚动和偏航,但我不明白如何将点转换为方向,特别是在用户旋转设备时。 理想情况下,我可以将这3个数字转换成一个单独的值,这个值总是能告诉我哪一个方法已经启动,而不必重新学习所有的三angular函数。 我已经看了3D茶壶的例子,但它并没有帮助,因为这个例子是二维,我不需要倾斜/朝着倾斜。 另外,我不想使用指南针/磁力计,因为这需要在iPod Touch上运行。

我如何确定CALayer是否被其他CALayer完全覆盖?

我有一系列随机放置在屏幕上的图层。 随着每个图层的添加,它被定位在所有其他图层之上。 最终,一个图层被其他图层完全覆盖。 在这一点上,我想从内存中删除图层。 有什么方法可以知道一个图层何时被其他图层覆盖(100%或一些分数)? 每个图层都有一个旋转变换,所以我不能准确地在所有图层的框架之间进行比较。

如何在转换为video的同时对图像进行animation处理

我想平滑地将图像制作成animation,同时将它们转换为video。 尽pipe如此,我无法理解如何实现它。 我试图改变旋转angular度(CGAffineTransformRotation),翻译和缩放,但没有find一种方法来平滑的animation。 inheritance人如何将照片数组转换为video: – (void)createVideoWithArrayImages:(NSMutableArray*)images size:(CGSize)size time:(float)time output:(NSURL*)output { //getting a random path NSError *error; AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:output fileType:AVFileTypeMPEG4 error: &error]; NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: AVVideoCodecH264, AVVideoCodecKey, [NSNumber numberWithInt:size.width], AVVideoWidthKey, [NSNumber numberWithInt:size.height], AVVideoHeightKey, nil]; AVAssetWriterInput* videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings]; AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput: videoWriterInput sourcePixelBufferAttributes:nil]; videoWriterInput.expectsMediaDataInRealTime = YES; […]

如何实现执行contentStretch逆的UIView?

UIView contentStretch属性定义了内容被拉伸以填充视图的区域。 这是伟大的,但我发现自己需要的是完全相反的:我想要一个视图,我可以定义一个矩形不伸展,但有外边缘伸展,直到他们填充视图。 +——————————————-+ | | | +———-+ | | | | | | | | | | | Content | Stretch to fill | | | | | | | | | | +———-+ | | | +——————————————-+ 所以在上面的观点中,外观是我提出的观点。 内部矩形是不可拉伸的内容。 理想情况下,我希望能够将不可拉伸的内容的中心点定位在外部矩形内的任何位置,并仍然将外部位填充到边缘。 示例使用场景:带有透明中心“洞”的黑色覆盖层,跟随鼠标/触摸用于使用手电筒探索场景等。 我想这样做的一个方法是绘制内容UIView,然后绘制其他四个视图,适当的大小,以覆盖外部区域,但我希望为一个单一的解决scheme更stream畅的animation。 我猜我需要有一个单一的UIView,并使用核心animation下来,混乱它的图层?

iOS布局animation在GMSMapView拖动时忽略持续时间

你可以看到比较两个GIF下面的问题。 “缩小”和“拉伸”animation都基于约束操作, [self layoutIfNedeed]放置在-animateWithDuration块内。 正如你所看到的,当地图没有移动时,它就像预期的那样工作。 但是,当您开始拖动地图时,“缩小”animation会立即发生。 如果仔细观察,您可能会注意到cornerRadiusanimation仍然有效。 这告诉我,它可能与地图(scrollView里面?不知道如何谷歌地图工作)调用它自己的布局块,干扰我的animation。 或者这可能是由于cornerRadiusanimation是使用CABasicAnimation而不是UIViewanimation完成的。 animationInfoView不是mapView的子视图。 不知道当mapView调用内部布局方法时它是否会影响我的infoView的布局。 我试过所有的选项结合UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionOverrideInheritedDuration | UIViewAnimationOptionOverrideInheritedOptions UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionOverrideInheritedDuration | UIViewAnimationOptionOverrideInheritedOptions UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionOverrideInheritedDuration | UIViewAnimationOptionOverrideInheritedOptions只是为了看看是否有帮助。 它不是。 我想我可以直接克服这个操纵框架,而不是操纵约束,它会看起来一样的用户,但我觉得使用约束是如此的优雅。 我尽量避免操纵框架,并使用自动布局。 任何想法是什么导致这一点,以及如何使用自动布局animation克服这个问题? UPDATE 我试图直接animation框架 – 结果是一样的。 所以它与自动布局无关。 看起来像当前视图animation由于某种原因停止。 如果我用CABasicAnimationreplace我的UIViewanimation块,它就像一个魅力。 我被要求发布一些animation代码: – (void)shrink { if (!self.isStretched) return; self.stretched = NO; [self hideImageAndLabels]; [self.indicatorView startAnimating]; CABasicAnimation *animation = [CABasicAnimation […]

iphone开发:如何使用NSTimer创buildanimation

在我的应用程序中,我在viewWillAppear中有这个代码。 它只是将从屏幕顶部到底部的随机对象animation化。 问题是我需要检测碰撞,到目前为止我所学到的是不可能在任何时候检索animation的坐标。 那我该如何使用NSTimer来实现呢? 或者我应该使用NSTimer? 我无法弄清楚。 任何线索将不胜感激。 -(void)viewWillAppear:(BOOL)animated { for (int i = 0; i < 100; i++) { p = arc4random_uniform(320)%4+1; CGRect startFrame = CGRectMake(p*50, -50, 50, 50); CGRect endFrame = CGRectMake(p*50, CGRectGetHeight(self.view.bounds) + 50, 50, 50); animatedView = [[UIView alloc] initWithFrame:startFrame]; animatedView.backgroundColor = [UIColor redColor]; [self.view addSubview:animatedView]; [UIView animateWithDuration:2.f delay:i * 0.5f options:UIViewAnimationCurveLinear […]

CABasicAnimation完成1个周期后回到原来的位置

在下一个animation和Objective-C 之前不要将CABasicAnimation返回到原始位置 – animation之后应用更改的CABasicAnimation? 和CABasicAnimation旋转返回到我试过的原始位置 。 below code does,bottom->top->goes left->back to it's original position. bottom->top->goes left->back to its original position. I need bottom->top->goes left.bottom->top->goes left so on… -(void)addUpDownAnimationForButton:(UILabel*)label { CABasicAnimation * bottomAnimation ; bottomAnimation =[CABasicAnimation animationWithKeyPath:@"transform.translation.y"]; [bottomAnimation setValue:@"animation1" forKey:@"id"]; bottomAnimation.delegate = self; [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)]; bottomAnimation.duration = 2.0; bottomAnimation.fromValue = [NSNumber numberWithFloat:13]; bottomAnimation.toValue = [NSNumber numberWithFloat:-7]; […]

如何一起animation多个SKSpriteNode?

我对SpriteKit很新。 我有一组节点,需要一起移动到每个节点的不同点,然后完成所有animation的animation,我想做点别的。 我以前用UIView组件做这个。 [UIView animateWithDuration:completion:]块提供了我需要的东西。 但是在SpriteKit每个节点都有其自己的动作和animation。 我找不到任何精灵节点的块animation。 所以我无法控制animation完成。 希望,我很清楚。 提前致谢。

协调CACurrentMediaTime()和deviceCurrentTime

我正在尝试与AVAudioPlayer同步几个CABasicAnimations 。 我遇到的问题是,当AVAudioPlayer使用deviceCurrentTime时, CABasicAnimation使用CACurrentMediaTime()作为调度animation的参考点。 同样对于animation,使用CFTimeInterval ,而对于声音,它是NSTimeInterval (不知道是否像其他CF和NStypes“免费桥接”)。 我发现参考点也是不同的。 有没有办法确保声音和animation使用相同的参考点?