我试图通过激活UI按钮来制作一个从按钮上滑动的菜单。按下按钮时,UIscrollView会从底部向上滑动。当UI按钮未被激活时,该按钮也会保持在幻灯片菜单上方。
这里应该是什么样的:
我在实际项目中将屏幕锁定为纵向模式,问题是当您按下按钮时。 UIscrollView滑动到屏幕中间,当您再次按下按钮时,它只会向下移动几个。并且该按钮不会移动 WITH UIscrollView。我想这样做,所以UI scrollView和Unbutton就像上面的图片一样出现,并在屏幕视口下方 UNDER 。
这就是我的实际项目 - http://s4.postimg.org/dlvxnffbx/unnamed.png
以下是viewcontroller.m中动画的代码。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize scrollView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
draw1 = 0;
scrollView.frame = CGRectMake(0, 300, 480, 55);
[scrollView setContentSize:CGSizeMake(480, 55)];
openMenu.frame = CGRectMake(220, 270, 60, 30);
}
- (IBAction)OpenMenu:(id)sender {
if (draw1 ==0) {
draw1 = 1;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
[UIButton setAnimationDelay:0.0];
[UIButton setAnimationCurve:UIViewAnimationCurveEaseOut];
scrollView.frame = CGRectMake(0, 245, 568, 55);
openMenu.frame = CGRectMake(220, 200, 60, 30);
[self.view bringSubviewToFront:scrollView];
[UIView commitAnimations];
} else {
draw1 = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
[UIButton setAnimationDelay:0.0];
[UIButton setAnimationCurve:UIViewAnimationCurveEaseOut];
scrollView.frame = CGRectMake(0, 300, 568, 55);
openMenu.frame = CGRectMake(220, 270, 60, 30);
[self.view bringSubviewToFront:scrollView];
[UIView commitAnimations];
}
}
@end
答案 0 :(得分:2)
您是否尝试过更换:
if (draw1 ==0) {
draw1 = 1;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
[UIButton setAnimationDelay:0.0];
[UIButton setAnimationCurve:UIViewAnimationCurveEaseOut];
scrollView.frame = CGRectMake(0, 245, 568, 55);
openMenu.frame = CGRectMake(220, 200, 60, 30);
[self.view bringSubviewToFront:scrollView];
[UIView commitAnimations];
} else {
draw1 = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
[UIButton setAnimationDelay:0.0];
[UIButton setAnimationCurve:UIViewAnimationCurveEaseOut];
scrollView.frame = CGRectMake(0, 300, 568, 55);
openMenu.frame = CGRectMake(220, 200, 60, 30);
[self.view bringSubviewToFront:scrollView];
[UIView commitAnimations];
}
with:
if (draw1 ==0) {
draw1 = 1;
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
scrollView.frame = CGRectMake(0, 1000, 568, 55);
openMenu.frame = CGRectMake(220, 200, 60, 30);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
} else {
draw1 = 0;
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
scrollView.frame = CGRectMake(0, 300, 568, 55);
openMenu.frame = CGRectMake(220, 270, 60, 30);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
}
答案 1 :(得分:1)
如果您正在查看它应该从按钮滑动,意味着在开始时它的帧大小应为零并从按钮中心开始出现并且应该获得完整大小然后您应该在动画之前设置框架
下面的代码会在您想要打开时从屏幕底部显示scrollView,在关闭时它会隐藏屏幕底部的scrollView ...
在viewDidLoad方法中设置初始帧你想要什么...如果你想隐藏它然后设置scrollView的y位置大于superView的高度,在这种情况下它将隐藏底部的视图。
(draw) {
// to open
draw = 0;
[UIView animateWithDuration:1 animations:^{
scrollView.frame = CGRectMake(0, self.view.bounds.size.height - 55, self.view.bounds.size.width, 55);
openMenu.frame = CGRectMake(220, scrollView.frame.origin.y - 40, 60, 30);
}];
}
else
{
//close
draw = 1;
[UIView animateWithDuration:1 animations:^{
CGRectMake(0, self.view.bounds.size.height + 55, self.view.bounds.size.width, 55);
openMenu.frame = CGRectMake(220, scrollView.frame.origin.y - 40, 60, 30);
}];
}