簡體   English   中英

將按鈕從UIView拖放到另一個UIVview

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

我已經使用了90個按鈕和視圖,按鈕必須從一個視圖移動到另一視圖,並且標記值必須相同,只有視圖必須更改。

嗨,終於我得到了我的問題的答案

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