我的视野中有一个UIButton。在按钮的触摸事件中,我会出现一个UIView。我使用的UIAnimation使视图从窗口顶部出现。但我希望它能出现在。触摸按钮之前,视图是不可见的。在触摸按钮时,视图应该从上面的位置开始出现。
以下是代码:
-(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];
}这就是我如何再一次隐藏观点:
-(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];
}在viewDidLoad中,我执行以下操作:
CGRect rect = viewInfo.frame;
rect.origin.y = -rect.size.height;
viewInfo.frame = rect; 更新:
请参阅这示例。这里的视图从屏幕顶部出现。我想要它出现在按钮y轴。关于那件事,请考虑一下y键的位置。
发布于 2012-02-27 12:47:57
所以你想要一个幻灯片效果,但不是从屏幕的顶部,只是一些任意的值?
一种方法是:
1)在动画完成后,您应该创建一个具有所需视图的尺寸和位置的视图,我们将称之为call视图。
2)将基视图属性clipsToBounds设置为YES。这将使基视图框架之外的所有子视图不可见。
3)将动画视图添加为基视图的子视图,但将框架设置为不可见(通过将其设置在基视图之上):
frame = CGRectMake(0, -AnimViewHeight, AnimViewWidth, AnimViewHeight);4)动画化动画框架:
//put this inside of an animation block
AnimView.frame = CGRectMake(0, 0, AnimViewWidth, AnimViewHeight);编辑:
示例:
//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];
}];
}发布于 2012-02-29 18:49:39
我已经做了你在我最近的项目中尝试过的事情。应该通过以下步骤来完成这项工作: 1.在您的viewDidLoad:中,您可以像下面这样插入viewToFadeIn:
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.您的ShowInfowView:方法应该如下所示:
` -(IBAction) ShowInfowView:(Id)发件人{
[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.yourHideInfoView:‘方法如下所示
-(IBAction) HideInfoView:(id)sender{
[UIView beginAnimations:@"fadeOut" context:NULL];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelegate:self];
viewToFadeIn.transform = CGAffineTransformMakeTranslation(0, 0);
[UIView commitAnimations];
}编辑: 4. animationFinishedMethod:
- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context{
if ([animationID isEqual:@"fadeIn"]) {
//Do stuff
}
if ([animationID isEqual:@"fadeOut"]) {
//Do stuff
}
}请参阅这
这应该能起作用。祝好运
发布于 2012-02-27 09:22:12
你的问题(对我来说)不清楚。这是什么?
rect.origin.y = rect.size.height - rect.size.height+58.0;58是你UIButton的来源吗?
您应该使用sender.frame等
使用块来像这样动画
[UIView animateWithDuration:0.5f animations:^{
// Animation here
} completion:^(BOOL finished) {
// onComplete
}];https://stackoverflow.com/questions/9462410
复制相似问题