Question

i'm still a beginner in xcode. here is my problem.. i have a scrollview made programitaically in which there is a uilabel made inside it programmically. i have placed the ssrollview in the edge of the view controller so that it is invisible. i want to animate it to slide and appear in the viewcontroller when a button is pressed. how do i do this? it works very well when i am only animating the scrollview only but i'm not able to animate the scrollview when the uilabel is placed inside it.. here's the i used. the following block is from a button action.[note: i have used quartzcore framework]

    -(IBAction)slideback:(id)sender

{

viol=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 44.8, 320, 420)];
viol.contentSize=CGSizeMake(320, 900);
viol.showsVerticalScrollIndicator=YES;
viol.backgroundColor=[UIColor grayColor];
    viol.delegate=self;



CATransition *animation = [CATransition animation];

[animation setDuration:1];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[viol layer] addAnimation:animation forKey:@"SlideView"];

l1=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 700)];
l1.backgroundColor=[UIColor redColor];
l1.font=[UIFont boldSystemFontOfSize:16];
[l1 setNumberOfLines:0];
[l1 sizeToFit];
[viol addSubview:l1];

[self.view addSubview:viol];

}

Was it helpful?

Solution

The code is fine. It will work once you setText to UILabel, You have used [l1 sizeToFit];

sizeToFit resizes and moves the view so it encloses its subviews. Since you dont have text in UILabel its width and height will be (0,0)

-(IBAction)slideback:(id)sender {
  viol=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 44.8, 320, 420)];
viol.contentSize=CGSizeMake(320, 900);
viol.showsVerticalScrollIndicator=YES;
viol.backgroundColor=[UIColor grayColor];
viol.delegate=self;

[self.view addSubview:viol];


l1=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 700)];
l1.backgroundColor=[UIColor redColor];
l1.font=[UIFont boldSystemFontOfSize:16];
[l1 setNumberOfLines:0];
//    [l1 sizeToFit];
[viol addSubview:l1];

CATransition *animation = [CATransition animation];
[animation setDuration:2];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];


[[l1 layer] addAnimation:animation forKey:@"SlideView"];

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top