我想为一个游戏制作动画片,我想让这些片段向不同的方向移动,这样我现在的动画整个视图的方法将不再适用.
我想知道一次动画多个项目的最佳做法是什么.(注意我在2d渲染所以我目前对3d解决方案不感兴趣.)
谢谢!
我正在尝试实现轮式功能.我计算视图的中心点,并找到在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) 我一直在研究一个新的应用程序,并且真的希望实现一次滑动以在我的应用程序中显示更多选项菜单.我进行了搜索和搜索,但似乎没有其他人成功地使其工作(除了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) 如何在没有动画的情况下向CALayer添加子图层?通常当你添加一个" 淡入 "时,当你删除一个它"淡出".
如何抑制动画?
我有一个与此非常相似的问题:
我只是想尝试使用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拍摄的图像像素化.
但我想最终实现这样的图像: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
我有一个已设置图像的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)
任何的想法?

在iOS 5的Messages.app显示中,任何人都可以解释如何最好地模仿"附件视图"(在倒置逗号中,因为我实际上并不认为它是附件视图)的行为,因为我想要一个给人留下深刻印象的视图它固定在键盘顶部,但在键盘解除后仍保留在屏幕上.
我有一些iOS示例代码,如果我点击主视图并点击处理程序更改CALayer对象的frame属性,图层对象将设置其位置和大小的动画.
但是,如果我把动画里面ViewController的viewDidLoad:
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)没有动画的.为什么这样以及如何使其发挥作用?
core-animation ×10
iphone ×8
objective-c ×5
ios ×3
calayer ×2
2d ×1
uiimageview ×1
uitableview ×1
uiview ×1