如何将对象移动到安排位置? [英] How to move object to arrangement?
问题描述
所有人
我有一个问题,我想实现一个UI,就像iOS桌面一样,到目前为止我可以安排
I got a question , I want to implement a UI , Like iOS desktop , so far I can arrangement
对象:
int k=0;
int j;
for (int i=0; i<[items count]; i++) {
//k is row
j=i%3;
if (j==0) {
k++;
if (k%3 == 1) {
k = 1;
}
}
[button setFrame:CGRectMake(25+(i%3*95), 35+((k-1)*140), 100, 100)];
因此,视图将如下所示
A B C
D E F
G H I
现在,使其进入编辑模式,在E和F之间拖动A
Now , let it into edit mode , drag A drop between E and F
所以有很多事情要做
B和C将向左移动,D将在B C之后上升
B and C will shift to left , D will go up after B C
E左移.(如何实现这些动画?)
E shift left .(how to implement these animations ???)
B C D
E A F
G H I
我搜索了Apple示例,只找到了Moveme这个示例,但它只有一个对象
I search the Apple sample , I only find Moveme this sample , but it only one object
任何建议或示例代码都会有很大帮助:)
Any advise or sample code will be great help : )
谢谢
Webber
推荐答案
用户移动按钮时,必须首先找到它的新索引.
When the user moves a button, you have to find it's new index first.
int j = (button.frame.origin.x - 25) / 95;
int k = (button.frame.origin.x - 35) / 140;
int newIndex = 3 * k + j;
然后,您必须将其放置在items数组中的该索引处.
Then you have to place it at that index in the items array.
[items insertObject:button atIndex:newIndex];
然后,您应该调用提供的代码来重新定位按钮.
Then you should call the code you provided to reposition the buttons.
for (int i = 0; i < items.count; i++) {
UIButton *button = (UIButton *)[items objectAtIndex:i];
[UIView animateWithDuration:0.5 animations:^{
button.frame = CGRectMake(25+(i%3)*95, 35+(i/3)*140, 100, 100);
}];
}
这篇关于如何将对象移动到安排位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!