Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

IDMah

macrumors 6502
Original poster
May 13, 2011
317
11
Hey Gang.

For some reason I can move a view off the scrollView but not on.. :confused:

I have tagged the view With numbers e.g. 105 104 103 102 101,100. because they correspond to the object in a mutable array and I have had problems with view tagged zero. So I delete UIView 100 and want to slide the
view 101 to where the >>>100 was. then I rebuild the scroll view.

the adding code works but the ENDREMOVEMODE does not..

Code:
-(void)viewToMoveTag:(UIView *)viewMoving insert:(NSInteger)inserting durationTiming:(CGFloat)duration
{
CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;
	
	// Setup the animation
	
	[UIView beginAnimations:@"slideAnim" context:nil];
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDuration:duration];
	//[UIView setAnimationCurve:curve];
	[UIView setAnimationDidStopSelector:@selector(slideDone:finished:context:)];
	[UIView setAnimationBeginsFromCurrentState:YES];
	
	self.navigationController.navigationBar.userInteractionEnabled = NO;   //for  disabling Nav Buttons 
	[scrollView setScrollEnabled:NO];

if (inserting==ADDMODE) {
		NSLog(@"ADD MODE Animation");
		self.modeInSDel = ADDMODE;
		CGAffineTransform transform = CGAffineTransformMakeTranslation(viewMoving.frame.size.width,0);
		viewMoving.transform = transform;
		// Commit the changes //
		[UIView commitAnimations];
		
	}
	
	if (inserting==ENDREMOVEMODE) {
		[viewMoving setAlpha:1];
		NSLog(@"ENDMOVE MODE Animation %i",[viewMoving tag]);
		self.modeInSDel = ENDREMOVEMODE;
		viewMoving = [scrollView viewWithTag:(1+[viewMoving tag])];
		//[viewMoving setAlpha:1];
		
		NSLog(@"intial state: %f",viewMoving.frame.origin.x);
		NSLog(@"actually moving View: %i",[viewMoving tag]);
		CGAffineTransform transform = CGAffineTransformMakeTranslation(viewMoving.frame.size.width,0);
		//CGAffineTransform transform = CGAffineTransformMakeTranslation(100,0);
		
		viewMoving.transform = transform;
		NSLog(@"moving to: %f",viewMoving.frame.origin.x);
		[UIView commitAnimations];
	}
}

if I want the movement to take a 6 seconds so that's why I'm not just scrolling there.

thanks all
Ian
 
How the Scrollview was setup..

Here is how I setup the scrollview.

Code:
-(void)rebuildScrollView
{

	
	[scrollView setScrollEnabled:YES];
	// clear the Scrollview first //
	/*
	for(UIView *subview in [scrollView subviews]) {
		if([subview isKindOfClass:[UIView class]]) {
			[subview removeFromSuperview];
		} else {
			// Do nothing - not a UIButton or subclass instance
		}
	}
	*/
	NSArray *subviews = [[scrollView subviews] copy];
	for (UIView *subview in subviews) {
		[subview removeFromSuperview];
	}
	[subviews release];
	
	for (NSInteger i = 0; i < [[company myCards]count]; i++) {
		//NSInteger i=0;
		CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;
		
        UIView *subview = [[UIView alloc] initWithFrame:frame];
        // add current card first then other cards //
		
		CardView *addAScrollableCard = [[CardView alloc]initWithFrame:CGRectMake(9,2, frame.size.width*.94, frame.size.height*.94)];
		//[addAScrollableCard drawCard:[[company myCards]objectAtIndex:i toCompany:company]];
		//addAScrollableCard=[myCardView drawCard:[[company myCards]objectAtIndex:[company currentCardIndex]] toCompany:company];
		[addAScrollableCard drawCard:[[company myCards] objectAtIndex:(([[company myCards]count]-1)-i)] toCompany:company];
		
		if ([[[company myCards] objectAtIndex:(([[company myCards]count]-1)-i)] cardCommander]==CARDFULL) {
			[[[company myCards] objectAtIndex:(([[company myCards]count]-1)-i)] setCardCommander:NOANIMATE];
			[company setWillNeedANewCard:YES];
		}
		
		if ([[[company myCards] objectAtIndex:(([[company myCards]count]-1)-i)] cardCommander]==NEWCARDANIMATE)
		{
			subview.alpha=0.0;
			NSLog(@"A fade Card");
			[UIView beginAnimations: @"Fade In" context:nil];
			
			// wait for time before begin
			//	[UIView setAnimationDelay:wait];
			
			// druation of animation
			[UIView setAnimationDuration:6.0];
			subview.alpha = 1;
			[UIView commitAnimations];
			[[[company myCards]objectAtIndex:([[company myCards]count]-1-i)] setCardCommander: NOANIMATE];
		}
		[subview addSubview:addAScrollableCard];	 
		subview.backgroundColor = [UIColor clearColor];
		subview.tag = 100+[[company myCards]count]-i;
		NSLog(@"creating views with tag: %i at X:%f ",subview.tag,frame.origin.x );
		
		//if (([[company myCards]count]-i)>=0) {
			[self.scrollView addSubview:subview];
		//}
		[subview release];
		//[addAScrollableCard release];
		NSLog(@" ********  adding View %i to ScrollView tag= %i *********",i,([[company myCards]count]-i));
	}
	self.pageControl.numberOfPages = [[company myCards]count];
	frame.origin.x = self.scrollView.frame.size.width * ([[company myCards]count]-1);
	frame.origin.y = 0;
	
	NSLog(@"**** populating Scroll view with %i views",[[company myCards]count]);
	//self.pageControl.numberOfPages = 1;
	pageControlBeingUsed=NO;
	
	//[scrollView setScrollEnabled:NO];
	// frame.size.width, * colors.count 
    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width*[[company myCards]count], self.scrollView.frame.size.height);
	
	// ************ scroll rate ************* //
	self.scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
	//  ReEnable Navigation //
	self.navigationController.navigationBar.userInteractionEnabled = YES;
	
	// freak n' hackey but works shrug  !! //
	[[self.scrollView viewWithTag:0]setTag:100];
	[company setCurrentCardIndex:[[company myCards]count]-1]; 
}

I NSLoged the Move routine the numbers look right..

Code:
moving last card
2012-04-27 03:02:09.866 PooJuV2[1090:207] ENDMOVE MODE Animation 100
2012-04-27 03:02:09.867 PooJuV2[1090:207] intial state: 642.000000
2012-04-27 03:02:09.867 PooJuV2[1090:207] actually moving View: 101
2012-04-27 03:02:09.868 PooJuV2[1090:207] moving to: 963.000000

2012-04-27 03:02:14.870 PooJuV2[1090:207] (-) End Card Delete Animation is Done
2012-04-27 03:02:14.871 PooJuV2[1090:207] company Class removing card:0

I finally figured out that the tags were off one.. shrug. but feels hackey but works by adding one to the calling function 102 not 101. too lazy to track down why because it will break everything else.. QED "HAckey.. "
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.