UIAnimation-mostra UIView do botão.quadro.origem.y
UIView
. O UIAnimation
que eu usei faz com que a vista apareça do topo da janela. Mas quero que apareça do botão.quadro.origem.y. Antes de tocar no botão, a vista não está visível. Ao tocar na janela do botão deve começar a aparecer de cima da posição.
Aqui está o código:
-(IBAction) ShowInfowView:(id)sender{
CGRect rect = viewInfo.frame;
rect.origin.y = rect.size.height - rect.size.height+58.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.70];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
viewInfo.frame = rect;
[UIView commitAnimations];
}
É assim que estou a esconder a vista outra vez.
-(IBAction) HideInfoView:(id)sender{
CGRect rect = viewInfo.frame;
rect.origin.y = -rect.size.height;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.70];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
viewInfo.frame = rect;
[UIView commitAnimations];
}
no viewDidLoad estou a fazer o seguinte :
CGRect rect = viewInfo.frame;
rect.origin.y = -rect.size.height;
viewInfo.frame = rect;
actualizar:
Por favor Veja isto exemplo. Aqui a vista está aparecendo do topo da tela. Quero que apareça do eixo do botão Y. Já agora, por favor, considere a posição do botão y um pouco para cima.
4 answers
Uma maneira de o fazer:
1) você deve criar uma vista que tenha as dimensões e a posição da sua vista desejada depois de a animação terminar, chamar-lhe-emos baseview.
2) definir esta propriedade baseview clipstounds para Sim . Isto tornará invisíveis todas as visões que estão fora do quadro de baseview .
3) Adicione a sua janela de animação como uma sub-janela do baseview , mas defina a moldura para que seja invisível (ao colocá-la acima de a baseview):
frame = CGRectMake(0, -AnimViewHeight, AnimViewWidth, AnimViewHeight);
4) animar a imagem:
//put this inside of an animation block
AnimView.frame = CGRectMake(0, 0, AnimViewWidth, AnimViewHeight);
Editar:
Exemplo:
//define the tags so we can easily access the views later
#define BASEVIEW_TAG 100
#define INFOVIEW_TAG 101
- (void) showInfo
{
//replace the following lines with preparing your real info view
UIView * infoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[infoView setBackgroundColor: [UIColor yellowColor]];
[infoView setTag: INFOVIEW_TAG];
//this is the frame of the info view AFTER the animation finishes (again, replace with real values)
CGRect targetframe = CGRectMake(100, 100, 100, 100);
//create an invisible baseview
UIView * baseview = [[UIView alloc] initWithFrame:targetframe];
[baseview setBackgroundColor: [UIColor clearColor]];
[baseview setClipsToBounds: YES]; //so it cuts everything outside of its bounds
[baseview setTag: BASEVIEW_TAG];
//add the nfoview to the baseview, and set it above the bounds frame
[baseview addSubview: infoView];
[infoView setFrame:CGRectMake(0, -infoView.bounds.size.height,
infoView.bounds.size.width, infoView.bounds.size.height)];
//add the baseview to the main view
[self.view addSubview: baseview];
//slide the view in
[UIView animateWithDuration: 1.0 animations:^{
[infoView setFrame: baseview.bounds];
}];
//if not using ARC, release the views
[infoview release];
[baseview release];
}
- (void) hideinfo
{
//get the views
UIView * baseView = [self.view viewWithTag: BASEVIEW_TAG];
UIView * infoView = [baseView viewWithTag: INFOVIEW_TAG];
//target frame for infoview - slide up
CGRect out_frame = CGRectMake(0, -infoView.bounds.size.height,
infoView.bounds.size.width, infoView.bounds.size.height);
//animate slide out
[UIView animateWithDuration:1.0
animations:^{
[infoView setFrame: out_frame];
} completion:^(BOOL finished) {
[baseView removeFromSuperview];
}];
}
viewDidLoad:
tu initas o teu viewToFadeIn
Assim:
viewToFadeIn = [[UIView alloc] initWithFrame:CGRectMake(20,self.view.frame.size.height+10, self.view.frame.size.widh-40, 200)];
//its important to initalize it outside your view
//your customization of this view
[self.view addSubview:viewToFadeIn];
2.o seu método deve ser o seguinte:
' - (IBAction) ShowInfowView: (id)sender {[[11]}
[UIView beginAnimations:@"fadeIn" context:NULL];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
viewToFadeIn.transform = CGAffineTransformMakeTranslation(0, -290);
//290 is in my case, try a little for your correct value
[UIView commitAnimations];
}
3.your
HideInfoView: 'o método parece-se com este
-(IBAction) HideInfoView:(id)sender{
[UIView beginAnimations:@"fadeOut" context:NULL];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelegate:self];
viewToFadeIn.transform = CGAffineTransformMakeTranslation(0, 0);
[UIView commitAnimations];
}
Editar:
4. animationFinishedMethod:
- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context{
if ([animationID isEqual:@"fadeIn"]) {
//Do stuff
}
if ([animationID isEqual:@"fadeOut"]) {
//Do stuff
}
}
VER ISTO
Isto deve servir. Boa sorte.rect.origin.y = rect.size.height - rect.size.height+58.0;
A origem do UIButton é 58?
Deve usar o remetente.frame etc
Usar blocos para animar assim
[UIView animateWithDuration:0.5f animations:^{
// Animation here
} completion:^(BOOL finished) {
// onComplete
}];
- (void) slideIn{
//This assumes the view and the button are in the same superview, if they're not, you'll need to convert the rects
//I'm calling the animated view: view, and the button: button...easy enough
view.clipToBounds = YES;
CGRect buttonRect = button.frame;
CGRect viewRect = CGRectMake(buttonRect.origin.x, buttonRect.origin.y + buttonRect.size.height, view.bounds.size.width, 0);
CGFloat intendedViewHeight = view.height;
view.frame = viewRect;
viewRect.size.height = intendedViewHeight;
[UIView animateWithDuration:.75 delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
view.frame = viewRect;
}completion:nil];
}
Isto fará com que a vista pareça deslizar por baixo do botão. Para deslizar a vista de volta, você apenas inverte as animações. Se quiser deslizá-lo do botão, terá de se certificar de que o seu 'y' inicial é o valor 'y' do botão (em vez da altura 'y'+') e animar tanto os valores de altura como de y da vista que necessita de ser animada.