Objective-c 隐藏视图动画

发布于 2024-11-03 02:35:49 字数 578 浏览 0 评论 0原文

您好,我的视图中有一个隐藏视图,通过单击按钮即可显示。但是,当您单击按钮时,我希望视图执行向上滑动动画,这样它不仅会出现,而且会向上滑动到其位置。

这是我的隐藏视图的代码: 在 .h 中:

@interface hidden_viewsViewController : UIViewController {

    IBOutlet UIView *loginview;

}

@property (nonatomic, retain) IBOutlet UIView *loginview;

- (IBAction)login;
- (IBAction)logout;

在 .m 中

@synthesize loginview;

- (IBAction)login {

    loginview.hidden = NO;

}

- (IBAction)logout {

    loginview.hidden = YES;

}

- (void)viewDidLoad {
    [super viewDidLoad];

    loginview.hidden = YES;
}

Hello I have a hidden view inside of my view that appears by the click of a button. But when you click on the button I want the view to do an slide up animation so it won't just appear but slide up to it's position.

Here is the code for my hidden view:
in .h:

@interface hidden_viewsViewController : UIViewController {

    IBOutlet UIView *loginview;

}

@property (nonatomic, retain) IBOutlet UIView *loginview;

- (IBAction)login;
- (IBAction)logout;

And in .m

@synthesize loginview;

- (IBAction)login {

    loginview.hidden = NO;

}

- (IBAction)logout {

    loginview.hidden = YES;

}

- (void)viewDidLoad {
    [super viewDidLoad];

    loginview.hidden = YES;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

べ繥欢鉨o。 2024-11-10 02:35:49

尝试一下,假设视图是纵向的:

- (IBAction)login {
    [self.view bringSubviewToFront:loginView];
    loginview.frame = CGRectMake(0, 480, 320, 480); 
    loginview.hidden = NO;
    [UIView animateWithDuration:1.0 
                     animations:^{
                         loginview.frame = CGRectMake(0, 0, 320, 480);
                     }];
}

Try, assuming the view is in portrait orientation:

- (IBAction)login {
    [self.view bringSubviewToFront:loginView];
    loginview.frame = CGRectMake(0, 480, 320, 480); 
    loginview.hidden = NO;
    [UIView animateWithDuration:1.0 
                     animations:^{
                         loginview.frame = CGRectMake(0, 0, 320, 480);
                     }];
}
小情绪 2024-11-10 02:35:49

您应该更改视图的框架属性,并且应该在动画块内执行此操作,如下所示:

-(IBAction)login
{
    [UIView beginAnimations:@"showView" context:nil];
    [UIView setAnimationDuration:0.5];
    CGRect viewNewFrame = self.view.frame;
    viewNewFrame.origin.y = 0;
    self.view.frame = viewNewFrame;
    [UIView commitAnimations];
 }

希望它有帮助!

you should change the frame property of your view, and you should do it within an animations block, as follows:

-(IBAction)login
{
    [UIView beginAnimations:@"showView" context:nil];
    [UIView setAnimationDuration:0.5];
    CGRect viewNewFrame = self.view.frame;
    viewNewFrame.origin.y = 0;
    self.view.frame = viewNewFrame;
    [UIView commitAnimations];
 }

Hope it helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文