当前位置:  编程技术>移动开发
本页文章导读:
    ▪模拟HUD, 乃是那种loading等待的对话框框        模拟HUD, 就是那种loading等待的对话框框 这个是网上抄袭的,改了改:   #import <UIKit/UIKit.h> @interface LoadingView : UIView { @private UIActivityIndicatorView *activityView; UIView *container; } - (id)initWithUIVie.........
    ▪ 那类别似toolbar可以提拖动的        那种类似toolbar可以提拖动的 最开始, 是想利用toolBar来着,可惜好多原因(忘了?好像是图片要自动给你光化,如果利用custom button也有这些那些的问题, 还有就是间距什么的, 位置也不好算).   最终.........
    ▪ 播音接收者(BroadcastReceiver)       广播接收者(BroadcastReceiver) 广播接收者(BroadcastReceiver)用于异步接收广播Intent,广播Intent的发送是通过调用Context.sendBroadcast()、Context.sendOrderedBroadcast()或者Context.sendStickyBroadcast()来实现.........

[1]模拟HUD, 乃是那种loading等待的对话框框
    来源: 互联网  发布时间: 2014-02-18
模拟HUD, 就是那种loading等待的对话框框

这个是网上抄袭的,改了改:

 

#import <UIKit/UIKit.h>


@interface LoadingView : UIView {
	@private
	UIActivityIndicatorView *activityView;
	UIView *container;
}

- (id)initWithUIView:(UIView *)aView message:(NSString *)msg;
- (void) show;
- (void) hide;
@end

 

 

#import "LoadingView.h"



@implementation LoadingView


- (id)initWithUIView:(UIView *)aView message:(NSString *)msg {
	CGRect containerBounds = aView.bounds;
    if ((self = [super initWithFrame:aView.bounds])) {
		UIColor* bgColor = [[UIColor alloc] initWithRed: 128/255.0 green:138/255.0 blue:135/255.0 alpha:1];
		[self setBackgroundColor:bgColor];
		[bgColor release];
		
		UIView *content = [[UIView alloc] initWithFrame:CGRectMake((containerBounds.size.width - 200) / 2, (containerBounds.size.height - 100) / 2, 200, 100)];
		UIImageView *imageview = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"rssloading.png"]];
		imageview.frame = CGRectMake(0.0, 0.0, content.frame.size.width, content.frame.size.height);

		[content addSubview:imageview];
		[imageview release];
		
		
        activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
		activityView.frame = CGRectMake(80, 20, 37.0f, 37.0f);
		[content addSubview:activityView];
		
		CGRect nameLabelRect = CGRectMake(0, 60, 200, 25);
		UILabel *titleLable = [[UILabel alloc] initWithFrame:nameLabelRect];
		titleLable.textAlignment = UITextAlignmentCenter;
		titleLable.text = msg;
		titleLable.font = [UIFont boldSystemFontOfSize:18];
		titleLable.alpha = 0.8;
		titleLable.backgroundColor = [UIColor clearColor];
		titleLable.textColor = [UIColor whiteColor];
		
		
		[content addSubview: titleLable];
		[titleLable release];		
		
		[self addSubview:content];
		[content release];
		
		
		[self setAlpha:0.67];
		[self setHidden:YES];
		
		container = aView;
		[container retain];
    }
    return self;
}

-(void) show {
	[container addSubview:self];
	[activityView startAnimating];
	[self setHidden:NO];
}
-(void) hide {
	[activityView stopAnimating];
	[self setHidden:YES];
	[self removeFromSuperview];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc {
	[activityView release];
	[container release];
    [super dealloc];
}


@end

 

效果图:



    
[2] 那类别似toolbar可以提拖动的
    来源: 互联网  发布时间: 2014-02-18
那种类似toolbar可以提拖动的

最开始, 是想利用toolBar来着,可惜好多原因(忘了?好像是图片要自动给你光化,如果利用custom button也有这些那些的问题, 还有就是间距什么的, 位置也不好算).

 

最终, 利用普通button + UIView + UIScrollView实现了个. 另外还悲剧的发现, 好像按钮没有长按时的那种事件..也是利用Timer自己搞.

 

 

@interface ScrollToolBar2 : UIView<UIScrollViewDelegate> {
	UIScrollView *buttonView;
	UIButton *leftButton;
	UIButton *rightButton;
	UIButton *selectedButton;
	int isTouchHold;
	NSTimer *timer;
}

- (id)initWithFrame:(CGRect)frame defaultClickButtonPosition:(int)pos images:(UIImage *)firstImg, ...;
@end

 

#import "ScrollToolBar2.h"
#define BUTTON_LEFT_SPACE 10
#define BUTTON_RIGHT_SPACE 10
#define BUTTON_ITEM_SPACE 10
#define BUTTON_MOVE_SPACE 6

@implementation ScrollToolBar2
void switchBtnState(UIButton *button)
{

	UIImage *imgA = [button imageForState:UIControlStateNormal];
	UIImage *imgB = [button imageForState:UIControlStateHighlighted];
	[imgA retain];
	[imgB retain];
	[button setImage:imgB forState:UIControlStateNormal];
	[button setImage:imgA forState:UIControlStateHighlighted];
	[imgA release];
	[imgB release];
}


- (void) toggle:(UIButton *) button
{
	if (selectedButton == button) {
		return;
	}

	if (selectedButton)
	{
		switchBtnState(selectedButton);
	}

	
	selectedButton = button;
	switchBtnState(button);
	float width = buttonView.frame.size.width;
	CGRect rect = button.frame;
	float offsetCenter = buttonView.contentOffset.x + width / 2;

	if((rect.origin.x + rect.size.width / 2) < offsetCenter) { // button in left
		float offset = rect.origin.x - (offsetCenter - rect.size.width / 2);
		CGPoint contentOffset = buttonView.contentOffset;
		contentOffset.x = contentOffset.x + offset;
		contentOffset.x = contentOffset.x < 0 ? 0 : contentOffset.x;
		[buttonView setContentOffset:contentOffset animated:YES];
	}
	else { //button in right
		float offset = rect.origin.x - (offsetCenter - rect.size.width / 2);
		CGPoint contentOffset = buttonView.contentOffset;
		contentOffset.x = contentOffset.x + offset;
		contentOffset.x = contentOffset.x > (buttonView.contentSize.width - width) ? (buttonView.contentSize.width - width) : contentOffset.x;
		[buttonView setContentOffset:contentOffset animated:YES];
	}
}



- (id)initWithFrame:(CGRect)frame defaultClickButtonPosition:(int)pos images:(UIImage *)firstImg, ...
{
	if ((self = [super initWithFrame:frame]))
	{
		UIButton *defaultClickBtn = nil;
		isTouchHold = 0;
		int i = 0;
		float totalWidth = BUTTON_LEFT_SPACE;
		va_list params;
		va_start(params, firstImg);
		UIImage *now = va_arg(params,UIImage *);
		UIImage *prev = firstImg;
		NSMutableArray *buttons = [[NSMutableArray alloc] init];
		while(firstImg)
		{
			UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
			[button setImage:prev forState:UIControlStateNormal];
			[button setImage:now forState:UIControlStateHighlighted];
			[button addTarget:self action:@selector(toggle:) forControlEvents:UIControlEventTouchDown];
			button.frame = CGRectMake(totalWidth, 0, prev.size.width, prev.size.height);

			button.tag = i;
			if (i == pos) {
				defaultClickBtn = button;
				[defaultClickBtn retain];
			}

			totalWidth += prev.size.width + BUTTON_ITEM_SPACE;
			[buttons addObject:button];

			i++;
			prev = va_arg(params,UIImage *);
			if(prev == nil)
			{
				break;
			}

			now = va_arg(params,UIImage *);
		}
		
		totalWidth = totalWidth - BUTTON_ITEM_SPACE + BUTTON_RIGHT_SPACE;
		buttonView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, frame.size.height)];
		buttonView.pagingEnabled = NO;
		buttonView.contentSize = CGSizeMake(totalWidth, frame.size.height);
		buttonView.showsHorizontalScrollIndicator = NO;
		buttonView.showsVerticalScrollIndicator = NO;
		buttonView.scrollsToTop = NO;
		
		for(id btn in buttons)
		{
			[buttonView addSubview:btn];
		}
		
		
		UIImage *leftBtnImg = [UIImage imageNamed:@"submenu_left"];
		leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
		leftButton.frame = CGRectMake(0.0, 0.0, leftBtnImg.size.width, leftBtnImg.size.height);
		[leftButton setImage:leftBtnImg forState:UIControlStateNormal];
		[leftButton retain];
		[leftButton addTarget:self action:@selector(offsetButtonTouchBegin:) forControlEvents:UIControlEventTouchDown];
		[leftButton addTarget:self action:@selector(offsetButtonTouchEnd:) forControlEvents:UIControlEventTouchUpInside];
		[leftButton addTarget:self action:@selector(offsetButtonTouchEnd:) forControlEvents:UIControlEventTouchUpOutside];
		
		UIImage *rightBtnImg = [UIImage imageNamed:@"submenu_right"];
		rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
		rightButton.frame = CGRectMake(frame.size.width - rightBtnImg.size.width, 0.0, rightBtnImg.size.width, rightBtnImg.size.height);
		[rightButton setImage:rightBtnImg forState:UIControlStateNormal];
		[rightButton retain];
		[rightButton addTarget:self action:@selector(offsetButtonTouchBegin:) forControlEvents:UIControlEventTouchDown];
		[rightButton addTarget:self action:@selector(offsetButtonTouchEnd:) forControlEvents:UIControlEventTouchUpInside];
		[rightButton addTarget:self action:@selector(offsetButtonTouchEnd:) forControlEvents:UIControlEventTouchUpOutside];
		

		UIImage *submenuBGImg = [UIImage imageNamed:@"submenu.png"];
		UIImageView *backgroundImg = [[UIImageView alloc] initWithImage:submenuBGImg];
		[self addSubview:backgroundImg];
		[self addSubview:buttonView];
		[self addSubview:leftButton];
		[self addSubview:rightButton];
		[self scrollViewDidEndDecelerating:buttonView ];
		[buttonView setDelegate:self];
		[backgroundImg release];
		[buttons release];
		
		if(defaultClickBtn) {
			[self toggle:defaultClickBtn];
			[defaultClickBtn release];
		}
	}
	
	return self;
}

- (void) transformation
{
	if (!timer) return;
	NSNumber *number = [timer userInfo];
	int offset = [number intValue];
	CGPoint offsetPoint = buttonView.contentOffset;
	offsetPoint.x = offsetPoint.x + offset;
	if (offsetPoint.x <= 0)
	{
		offsetPoint.x = 0;
		[timer invalidate];
		[timer release];
		timer = nil;
	}
	else if(offsetPoint.x >= (buttonView.contentSize.width - buttonView.frame.size.width))
	{
		offsetPoint.x = buttonView.contentSize.width - buttonView.frame.size.width;
		isTouchHold = 0;
		[timer invalidate];
		[timer release];
		timer = nil;
	}

	buttonView.contentOffset = offsetPoint;
}



- (void) startTimer:(id) sender
{
	int space = sender == leftButton ? BUTTON_MOVE_SPACE * -1 : BUTTON_MOVE_SPACE;
	NSNumber *number = [[NSNumber alloc] initWithInt:space];
	timer = [NSTimer scheduledTimerWithTimeInterval:0.005 target:self selector:@selector(transformation) userInfo:number repeats:YES];
	[timer retain];

	[number release];
}

- (void) offsetButtonTouchBegin:(id) sender
{
	isTouchHold = sender == leftButton ? -6 : 6;
	[self startTimer:sender];
}

- (void) offsetButtonTouchEnd:(id) sender
{
	[timer invalidate];
	[timer release];

	timer = nil;
	isTouchHold = 0;
}


void changeHiddenForButton(UIButton *button, BOOL isHidden)
{
	float alpha = isHidden ? 0.0 : 1.0;
	if (button.alpha == alpha) return;
	
	[UIView beginAnimations: nil context:nil];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	[UIView setAnimationDuration:1];
	button.alpha = alpha;

	[UIView commitAnimations];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
	[self scrollViewDidEndDecelerating:scrollView];
}



- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
	float offset = scrollView.contentOffset.x;
	if (offset <= 0)
	{
		changeHiddenForButton(leftButton, YES);
	}
	else 
	{
		changeHiddenForButton(leftButton, NO);
	}
	
	if(offset >= (scrollView.contentSize.width - scrollView.frame.size.width))
	{
		changeHiddenForButton(rightButton, YES);
	}
	else
	{
		changeHiddenForButton(rightButton, NO);
	}
}

- (void)dealloc
{
	[buttonView release];
	[super dealloc];
}

@end
 

这下代码够完整了吧...给公司写的,但是未经过测试,保佑不被老大发现.哈哈, 其实没啥技术含量, 反正都是你抄我, 我抄你..就是计算那些坐标系很是麻烦的说..

效果图:


 


    
[3] 播音接收者(BroadcastReceiver)
    来源: 互联网  发布时间: 2014-02-18
广播接收者(BroadcastReceiver)
广播接收者(BroadcastReceiver)
用于异步接收广播Intent,广播Intent的发送是通过调用Context.sendBroadcast()、Context.sendOrderedBroadcast()或者Context.sendStickyBroadcast()来实现的。通常一个广播Intent可以被订阅了此Intent的多个广播接收者所接收,广播接收者和JMS中的Topic消息接收者很相似。要实现一个广播接收者方法如下:
第一步:继承BroadcastReceiver,并重写onReceive()方法。
public class IncomingSMSReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
}
}
第二步:订阅感兴趣的广播Intent,订阅方法有两种:
第一种:使用代码进行订阅
IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
IncomingSMSReceiver receiver = new IncomingSMSReceiver();
registerReceiver(receiver, filter);
第二种:在AndroidManifest.xml文件中的<application>节点里进行订阅:
<receiver android:name=".IncomingSMSReceiver">
    <intent-filter>
         <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
    </intent-filter>
</receiver>

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3