IOS 代码片段 (Update!)

[b]1、分享到Facebook连接。[/b]

http://m.facebook.com/sharer.php?u=URL&t=标题


[b]2、移除ABPeoplePickerNavigationController右边的Cancel按钮[/b]

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.delegate = self;
.................

- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
// Here we want to remove the 'Cancel' button, but only if we're showing
// either of the ABPeoplePickerNavigationController's top two controllers
viewController.navigationItem.rightBarButtonItem = nil;
}

摘自:[url]http://stackoverflow.com/questions/1611499/abpeoplepickernavigationcontroller-remove-cancel-button-without-using-privat[/url]

[b]3.ios multipart request related code:[/b]

- (void) uploadPicture{

UIImage *img = [UIImage imageNamed:@"icon.png"];
NSData *imageData = UIImageJPEGRepresentation(img, 90);
//Here i tried 2 ways of getting the data for uploading, but both don't work.

// create the URL
NSURL *postURL = [NSURL URLWithString:@"http://*********/PictureUpload"];

// create the connection
NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:postURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];

// change type to POST (default is GET)
[postRequest setHTTPMethod:@"POST"];

// just some random text that will never occur in the body
NSString *stringBoundary = @"0xKhTmLbOuNdArY---This_Is_ThE_BoUnDaRyy---pqo";

// header value, user session ID added
NSString *headerBoundary = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",
stringBoundary];

// set header
[postRequest addValue:headerBoundary forHTTPHeaderField:@"Content-Type"];
// create data
NSMutableData *postBody = [NSMutableData data];

// text part
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"title\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"hello" dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];

// media/image part
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@.jpeg\"\r\n", @"helloImage"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Type: image/jpeg\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[NSData dataWithData:imageData]];
[postBody appendData:[@"Content-Transfer-Encoding: binary\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];

// final boundary
[postBody appendData:[[NSString stringWithFormat:@"--%@--\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *s = [[NSString alloc] initWithData:postBody encoding:NSASCIIStringEncoding];
NSLog(@"%@", s);

// add body to post
[postRequest setHTTPBody:postBody];

// pointers to some necessary objects
NSURLResponse* response;
NSError* error;

// synchronous filling of data from HTTP POST response
NSData *responseData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];

[NSURLConnection sendAsynchronousRequest:postRequest queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error)
{
NSLog(@"Error: %@", [error localizedDescription]);
}

// convert data into string
NSString *responseString = [[NSString alloc] initWithBytes:[responseData bytes]
length:[responseData length]
encoding:NSUTF8StringEncoding];

// see if we get a welcome result
NSLog(@"%@", responseString);
}];
}

See [url]http://stackoverflow.com/questions/8561403/multipart-formdata-image-upload-get-the-file[/url]
See [url]https://gist.github.com/1354221[/url]
See [url]http://en.wikipedia.org/wiki/MIME[/url]

4.Popup 效果弹出视图

CGAffineTransform transform = CGAffineTransformIdentity;
[self.view setTransform:CGAffineTransformScale(transform, 0.3, 0.3)];

[UIView animateWithDuration:0.2 animations:^{
[self.view setTransform:CGAffineTransformScale(transform, 1.1, 1.1)];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.13 animations:^{
[self.view setTransform:CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9)];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.13 animations:^{
[self.view setTransform:CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0)];
} completion:^(BOOL finished) {
//do nothing
}];
}];
}];


5.上下摇晃动画效果

CALayer*viewLayer=[self.inputHolderView layer];
CABasicAnimation*animation=[CABasicAnimation animationWithKeyPath:@"transform"];
animation.duration=0.1;
animation.repeatCount = 4;
animation.autoreverses=YES;
animation.fromValue=[NSValue valueWithCATransform3D:CATransform3DRotate(viewLayer.transform, -0.03, 0.0, 0.0, 0.05)];
animation.toValue=[NSValue valueWithCATransform3D:CATransform3DRotate(viewLayer.transform, 0.03, 0.0, 0.0, 0.05)];
[viewLayer addAnimation:animation forKey:@"wiggle"];


6.检查ARC的宏

#if !__has_feature(objc_arc)
[result autorelease];
#endif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值