我有一個短的音頻剪輯,按下按鈕時播放。我想從底部創建一個包含暫停/播放按鈕的滑塊控制器和一個顯示音頻長度的滑動條。我還希望控制器背後的視圖在控制器可見時保持可滾動狀態。我相信這不包括使用UIAlertView或UIActionSheetView,因爲它們都會導致下面的視圖保持靜態。什麼是實施這個最好的方法?用於音頻播放器控件的iPhone滑動視圖控制器?
編輯:我發現了一個有用的教程在這裏: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
我建議不要這樣做。這將是一個令人困惑的界面,並且很難通過編程來控制。有一個原因是行動表是模態的。 – TechZen 2010-11-14 18:56:45
如果執行得好,它當然可以運行imho。假設您按一個按鈕開始播放音頻文件。這些控件隨即出現在屏幕的底部,以便隨時播放/暫停等。不要以爲這會讓用戶感到困惑。同樣,如果正確完成的話。 – Rengers 2010-11-14 19:25:00
我正在考慮類似於NPR音樂應用的東西。它做得非常好,我認爲這是一個很好的解決方案,我正在尋找。 – alittlelost 2010-11-16 01:36:32