rexis.cn

一张相片 一段故事

Archive for the ‘objective-c’ tag

在iphone app中添加音量控制条

without comments

1. 添加MediaPlayer.framework
2. #import <MediaPlayer/MPVolumeView.h>
3. 代码

	MPVolumeView *volumeView = [[[MPVolumeView alloc]  initWithFrame:CGRectMake(18, 380, 284, 23)] autorelease];
	volumeView.center = CGPointMake(160,380);
	[volumeView sizeToFit];
	[self.view addSubview:volumeView];

Written by 北

七月 2nd, 2010 at 12:25 下午

Posted in iphone开发

Tagged with , ,

iphone程序中跳转到appstore评论界面

without comments

在程序中加入appstore的review跳转,实现方法很简单,就是让系统去打开一个review的链接,代码如下:

- (void) gotoWriteReviews {
	NSString* appID = NSLocalizedString(@"itunesconnect_appid", nil);	//这里是itunes connect生成的一串数字id
	NSString *u = [NSString stringWithFormat:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%@&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software",appID];
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:u]];
}

Written by 北

五月 25th, 2010 at 12:13 下午

Posted in iphone开发

Tagged with , ,

在图片上盖一层mask

without comments

- (UIImage*) createImage:(UIImage*)_image withMask:(UIImage*)_mask {
	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
	CGContextRef context = CGBitmapContextCreate(NULL,
						 _image.size.width,
						 _image.size.height,
						 8, 0,
						 colorSpace,
						kCGImageAlphaPremultipliedLast);
	CGColorSpaceRelease(colorSpace);
 
	CGRect rect = CGRectMake(0, 0, _image.size.width, _image.size.height);
	UIColor *bColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
	CGContextSetFillColorWithColor(context, [bColor CGColor]);                     //黑色是不透明,白色是透明
	CGContextFillRect(context, rect);
	CGContextClipToMask(context, rect, [_mask CGImage]);
	CGContextDrawImage(context, rect, [_image CGImage]);
 
	CGImageRef newImage = CGBitmapContextCreateImage(context);
	CGContextRelease(context);
 
	UIImage* _newImage = [[UIImage alloc] initWithCGImage:newImage];
	CGImageRelease(newImage);
 
	return [_newImage autorelease];
}

最先创建了一个灰度的颜色空间导致合成出来的mask颜色都是反的,黑色的显出白色,后来发现一篇例子是用RGB颜色空间来做再自己加上黑色填充后就得到了想要的效果,效果图:
lomo效果

Written by 北

五月 20th, 2010 at 11:59 下午

Posted in iphone开发

Tagged with , , ,