2011-09-08 79 views
15

我有一個UIView含有兩個UIButtons。子視圖滑塊,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