Сдвиньте UIView с помощью kCATransitionPush - PullRequest
5 голосов
/ 31 августа 2011

Я пытаюсь, чтобы UIView скользил вверх по четверти страницы, чтобы показать другой вид под ним (для отображения параметров), а затем скользил вниз, чтобы охватить эти параметры.Я искал ТАК безжалостно, но не могу найти то, что искал.Я не хочу использовать модальный вид, поскольку хочу сохранить вид сверху на экране.В приведенном ниже коде он вроде работает, верхний уровень скользит вверх, но затем полностью исчезает (исчезает).

Любая помощь с благодарностью!

Спасибо.

HomeOptionsViewController *homeOptionsViewController  = [[HomeOptionsViewController  alloc] 
                      initWithNibName:@"HomeOptionsViewController" 
                      bundle:nil];
// get the view that's currently showing
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];

UIView *newView = homeOptionsViewController.view; 
//newView.frame = CGRectMake(0,300, 320,140);
    newView.frame = CGRectMake(0,-10, 320,140);
// remove the current view and replace with myView1
//---[currentView removeFromSuperview];
[theWindow addSubview:newView];

theWindow.frame = CGRectMake(0,-110,320,200);

newView.frame = theWindow.bounds;
// set up an animation for the transition between the views

CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromTop];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
//[theWindow setFrame:CGRectMake(0,200,320,300)];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];

1 Ответ

3 голосов
/ 31 августа 2011

По какой причине вы не используете стандартную UIView анимацию?CATransitions полностью изменит представление, поскольку предполагается, что это переход от одного представления к другому.

Вы пробовали что-то подобное?Вы добавляете вид, который хотите сдвинуть с нижней части экрана, а затем анимируете изменение обоих кадров.Создает эффект скольжения.

newView.frame = CGRectMake(0,416,320,140);
[theWindow addSubview:newView];
[UIView beginAnimations:@"SwitchToView1" context:nil];
[UIView setAnimationDuration:0.5];
theWindow.frame = CGRectOffset(theWindow.frame, 0, -140);
newView.frame = CGRectOffset(newView.frame, 0, -140);
[UIView commitAnimations];
...