按下按钮时,我有一个简短的音频片段。我想从底部创建一个滑动控制器,其中包含一个暂停/播放按钮和一个显示音频长度的滑动条。我还希望控制器后面的视图在控制器可见时保持可滚动状态。我相信这不包括使用UIAlertView或UIActionSheetView,因为两者都会导致下面的视图保持静态。实现这个的最佳方法是什么?
编辑:我在这里找到了一个有用的教程:http://iosdevelopertips.com/user-interface/sliding-views-on-and-off-screen-creating-a-reusable-sliding-message-widget.html
我能够修改它以获得我想要的东西。但是,如果我想使用nib文件进行动画处理,我将如何调用它?
#import "SlidingMessageController.h"
@interface SlidingMessageController(private)
- (void)hideMsg;
@end
@implementation SlidingMessageController
#pragma mark -
#pragma mark Private Methods
- (void)hideMsg;
{
// Slide the view off screen
CGRect frame = self.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.75];
frame.origin.y = 480;
frame.origin.x = 0;
self.frame = frame;
//to autorelease the Msg, define stop selector
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
}
- (void)animationDidStop:(NSString*)animationID finished:(BOOL)finished context:(void *)context
{
[self removeFromSuperview];
[self release];
}
#pragma mark -
#pragma mark Initialization
- (id)initWithDirection:(int)dir;
//- (id)initWithTitle:(NSString *)title message:(NSString *)msg
{
if (self = [super init])
{
//Switch direction based on slideDirection konstant
switch (dir) {
case kSlideUp: //slideup
// Notice the view y coordinate is offscreen (480)
// This hides the view
// What should I be doing here if I want to get the nib file???
self.frame = CGRectMake(0,480,320, 90);
[self setBackgroundColor:[UIColor blackColor]];
[self setAlpha:.87];
newY = 380;
newX = 0;
myDir = 0;
break;
default:
break;
}
}
return self;
}
#pragma mark -
#pragma mark Message Handling
- (void)showMsgWithDelay:(int)delay
{
// UIView *view = self.view;
CGRect frame = self.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.75];
// Slide up based on y axis
// A better solution over a hard-coded value would be to
// determine the size of the title and msg labels and
// set this value accordingly
frame.origin.y = newY;
frame.origin.x = newX;
self.frame = frame;
[UIView commitAnimations];
// Hide the view after the requested delay
[self performSelector:@selector(hideMsg) withObject:nil afterDelay:delay];
}
#pragma mark -
#pragma mark Cleanup
- (void)dealloc
{
if ([self superview])
[self removeFromSuperview];
[super dealloc];
}
@end
答案 0 :(得分:2)
“滑动控制器”是什么意思?只是从底部向上滑动的视图?如果是这样,您可以使用其中的按钮创建一个UIView,并为其设置动画。对于动画,您可以使用UIView beginAnimations:context:
和commitAnimations
。