2011-09-08 7 views
15

Tengo una UIview que contiene dos UIButtons.Diapositiva de SubView en animación, 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]; 
} 

Quiero animar diapositivas en UIView de cuando se llama método siguiente.

-(void) showAnimation 

Traté de hacerlo de la siguiente manera, pero no puedo ver ninguna animación. ¿Cómo puedo hacerlo?

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

Thannks para cualquier ayuda de antemano.

Respuesta

60

Necesita agregar la subvista con un valor de marco que es donde desea que comience la animación (¿fuera de la pantalla?) Luego cambie el valor del marco dentro de su bloque de animación. El marco cambiará a lo largo de la duración, causando la apariencia de movimiento. La vista ya debe ser una subvista: no creo que agregar una subvista sea algo que puedas animar, no tiene sentido.

-(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

Muchas gracias ... Funcionó exactamente como se requiere .. – alekhine

+0

¿cuál es la salida? puedes mostrarme algo ... Necesito implementar eso – magid

Cuestiones relacionadas