Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically added subview doesn't interact with other views, but xib-added view worked fine
    text
    copied!<p>harlanhaskins wrote:</p> <p>I have a view called userSlider programmaticaly added in viewDidLoad:</p> <pre><code> self.userSlider = [[UserSliderView alloc] initWithFrame:CGRectMake(0, -120, 320, 155)]; [self.userSlider setUser:user]; [self.userSlider configureView]; [self.view addSubview:self.userSlider]; </code></pre> <p>And a tableview called gameTableView.</p> <p>I originally had added the userSlider into the xib as a custom view (because UserSlider has its own xib), and when I implemented these touch methods:</p> <pre><code> -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = (UITouch*)[touches anyObject]; start = [touch locationInView:self.view].y; } -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if(start &lt; 0) { return; } UITouch *touch = (UITouch *)[touches anyObject]; CGFloat now = [touch locationInView:self.view].y; CGFloat diff = now - start; sliderDirectionIsUp = diff &lt; 0; //sliderDirectionIsUp is a BOOL if ((self.userSlider.frame.origin.y == 0) &amp;&amp; ((now &lt; 120) || (now &gt; 155))) { return; } float newCenterY = self.userSlider.center.y + diff; if (newCenterY &lt; roundf(self.userSlider.frame.size.height / 2)) { self.userSlider.center = CGPointMake(self.userSlider.center.x, newCenterY); CGRect tableViewFrame = self.gameTableView.frame; tableViewFrame.origin.y += diff; tableViewFrame.size.height -= diff; [self.gameTableView setFrame:tableViewFrame]; } start = now; } -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CGRect tableViewFrame = self.gameTableView.frame; if (sliderDirectionIsUp) { tableViewFrame.origin.y = 28; tableViewFrame.size.height = (self.view.frame.size.height - tableViewFrame.origin.y); //animate userSlider out of visible area [UIView animateWithDuration:.3 animations:^{ self.userSlider.center = CGPointMake(self.userSlider.center.x, -roundf(self.userSlider.bounds.size.height/2.) + 35); [self.gameTableView setFrame:tableViewFrame]; }]; } else if(start &gt;= 0) { tableViewFrame.origin.y = (self.userSlider.frame.size.height - 7); tableViewFrame.size.height = (self.view.frame.size.height - tableViewFrame.origin.y); //animate userSlider with top to mainviews top [UIView animateWithDuration:.3 animations:^{ self.userSlider.center = CGPointMake(self.userSlider.center.x, roundf(self.userSlider.bounds.size.height/2.) - 0.5); [self.gameTableView setFrame:tableViewFrame]; }]; } } </code></pre> <p>then both views would move how I wanted them to.</p> <p>But now when I add it programmatically, suddenly the tableView doesn't change unless I tap inside the area after moving it. It's really weird.</p> <p>Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload