简体   繁体   English

将按钮从UIView拖放到另一个UIVview

[英]drag and drop the button from UIView to another UIVview

我已经使用了90个按钮和视图,按钮必须从一个视图移动到另一视图,并且标记值必须相同,只有视图必须更改。

Hi finally i got the answer of my question 嗨,终于我得到了我的问题的答案

- (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;
                             }
                         }
                     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM