2011-09-08 5 views
15

두 개의 UIButton이 포함 된 UIview가 있습니다.애니메이션의 하위 뷰 슬라이드, iPhone

-(void)ViewDidLoad 
{ 
    geopointView = [[UIView alloc] initWithFrame:CGRectMake(0, 350, 120, 80)]; 
    geopointView.backgroundColor = [UIColor greenColor]; 

    UIButton *showGeoPointButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; 
    showGeoPointButton.frame = CGRectMake(0, 0, 120, 40); 
    showGeoPointButton.titleLabel.font = [UIFont systemFontOfSize:13.0]; 
    [showGeoPointButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
[showGeoPointButton addTarget:self action:@selector(showPlaces:) forControlEvents:UIControlEventTouchUpInside]; 

    UIButton *SaveButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain] 
    SaveButton.frame = CGRectMake(0, 40, 120, 40); 
    SaveButton.titleLabel.font = [UIFont systemFontOfSize: 15.0]; 
    [SaveButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
    [SaveButton addTarget:self action:@selector(savePlacePopUp) forControlEvents:UIControlEventTouchUpInside]; 

    [geopointView addSubview:showGeoPointButton]; 
    [geopointView addSubview:SaveButton]; 
} 

나는 다음과 같은 메서드를 호출 할 때의 UIView의에 슬라이드를 애니메이션을 적용 할.

-(void) showAnimation 

나는 길을 따라 그것을 시도하지만 난 어떤 애니메이션을 볼 수 있습니다. 내가 어떻게 해?

-(void) showAnimation{ 
    [UIView animateWithDuration:10.0 animations:^{ 
     [self.view addSubview:geopointView]; 
    }]; 
} 

Thannks 사전에 도움이 필요합니다.

답변

60

애니메이션을 시작하고 싶지 않은 프레임 값을 가진 서브 뷰를 추가해야합니다 (오프 스크린?). 그런 다음 애니메이션 블록 내부의 프레임 값을 변경해야합니다. 프레임이 지속 시간 동안 변경되어 움직임이 나타납니다. 뷰는 이미 하위 뷰 여야합니다. 하위 뷰를 추가하는 것이 애니메이션으로 표현할 수있는 것이 아니라고 생각합니다.

-(void)showAnimation { 

    [self.view addSubview:geopointView] 
    geopointView.frame = // somewhere offscreen, in the direction you want it to appear from 
    [UIView animateWithDuration:10.0 
        animations:^{ 
         geopointView.frame = // its final location 
        }]; 
} 
+0

고마워 .. 정확히 필요한대로 작동했습니다. – alekhine

+0

출력은 무엇입니까 ?? 당신이 나에게 몇 가지를 보여줄 수 있습니까? – magid

관련 문제