我使用过90个按钮&视图,按钮必须从一个视图移动到另一个视图,并且标记值必须相同,只有视图必须更改。
答案 0 :(得分:0)
嗨,最后我得到了我的问题的答案
- (IBAction)reloadScrollView //reposition subviews or swap the subview
{
HButton *view = nil;
NSArray *subviews = [self.superview subviews];
NSInteger i = 0;
NSInteger FLAG=0;
[UIView beginAnimations:@"relayoutView" context:nil];
// To find and swap the subviews
for (view in subviews)
{
if ([view isKindOfClass:[HButton class]])
{
HButton *check=[subviews objectAtIndex:i];
if([self.titleLabel.text isEqualToString:@"1"])
{
if(![self.titleLabel.text isEqualToString:check.titleLabel.text])//check for same attribut if it is not it will enter
{
NSInteger Compare=check.tag-self.tag;
switch (Compare) {
// Horizontal
case -2:
{
// get the middle position from the check tag
NSInteger _new = check.tag +1;
// Linq Query - Kind of SQL Query
// from view in SubView
// where view.tag == _new
// select viwe
HButton *newCheck=[subviews objectAtIndex:_new];
if ([newCheck.titleLabel.text isEqualToString:@"1"])
{
// now check the value
rect1 = self.frame;
rect2 = check.frame;
if(CGRectIntersectsRect(self.frame,check.frame)) //check two subview intersecting or not
{
//your code for intersection here
FLAG++;
// NSLog(@"%d",FLAG );
int temptag;
temptag=self.tag;
self.tag=check.tag;
check.tag=temptag;
tempfrom=check;
tempto=self;
check.center=CGPointMake(homePosition.x , homePosition.y);
self.frame=rect2;
return;
}
}
}