【问题标题】:drag and drop the button from UIView to another UIVview将按钮从 UIView 拖放到另一个 UIVview
【发布时间】:2014-03-04 10:36:25
【问题描述】:

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

【问题讨论】:

  • 那里有很多相当难以阅读的代码,并且没有描述它做错了什么......
  • 几乎可以正常工作,但是标签值没有正确替换,如果您有任何示例源代码,请发给我.....@Wain
  • 是关心按钮标签值到下一个视图控制器的问题吗?
  • 如何使用按钮填充视图?它是 IB 文件还是您从数组/字典中获取它们?
  • 使用数组我正在检查特定标签的子视图..

标签: ios objective-c drag-and-drop


【解决方案1】:

你好,我的问题终于得到答案了

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

【讨论】:

  • [UIView beginAnimations:@"relayoutView" context:nil];这条线的目的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-24
相关资源
最近更新 更多