ios - 如何在 ios 中将四个图像从一个位置水平移动到另一个位置

标签 ios objective-c iphone

我有一个问题。我正在尝试在 iOS 中开发一款像 Abacus 这样的游戏。我想在 iOS 中将四张按顺序排列的图像从一个位置水平移动到另一个位置。任何人都可以帮助我请问我如何在 iOS 中执行此操作。我引用这个链接How to move Object from one place to other using Animation in iphone applications 但是使用它我只能水平移动一张图像我想移动四张图像我是怎么做到的。

这是我尝试过的:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch * touch = [touches anyObject]; 
    CGPoint loc = [touch locationInView:self.view]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:2.0]; 
    CGRect rect = CGRectMake(loc.x, _img.frame.origin.y, _img.frame.size.height, _img.frame.size.width); 
    [_img setFrame:rect]; 
    [UIView commitAnimations]; 
}

最佳答案

将所有图像放在一个 View 中(比如说容器 View ),然后移动容器 View

关于ios - 如何在 ios 中将四个图像从一个位置水平移动到另一个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31402794/

相关文章:

iphone - 在哪里可以获得具有 UITouchPhaseStationary 阶段的触摸事件?

ios - 我想在 iOS7 的 UI ScrollView 中更改按位置绑定(bind)的大小

ios - 动画结束后设置新的 Controller

iphone - 仅在为模拟器构建时复制符号

iphone - NSURLConnection 数据请求末尾没有数据

iphone - Cocoa 中的自动 "force repel"布局

iphone - 使用 iPhone 将图片发布到 Twitter

iphone - 添加自定义 UIButton 到 subview

ios - 如何检查 ios 中的互联网连接?

ios - 是否可以在 iOS 中获取移动数据 IP 地址? (不是服务提供商的公共(public) IP)