//AFN函数 — imageview载入网络图片而且获取图片,获取之后存储到手机
[image
setImageWithURLRequest
:[
NSURLRequest
requestWithURL
:[
NSURL
URLWithString
:[
NSString
stringWithFormat
:
@"%@"
,skin.
bigImg
]] ]
placeholderImage
:
nil
success
:^(
NSURLRequest
*request,
NSHTTPURLResponse
*response,
UIImage
*image) {
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
- (
void
)image:(
UIImage
*)image didFinishSavingWithError:(
NSError
*)error contextInfo:(
void
*)contextInfo
{
if
(error) {
[
self
showToastWithText
:
@"
不同意保存
"
];
}
else
{
[
self
showToastWithText
:
@"
保存成功
"
];
}
}
_player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:file] error:nil];
// NSLog(@"%@",[NSURL fileURLWithPath:file]);
// [_player play];
//audioplayer第三方类库播放文件
AudioPlayer
*player = [
AudioPlayer
sharePlayer
];
[player playWithDataSourceType:DataSourceTypeLocal withURLString:file];
//下载文件
NSString
*string = [
NSString
stringWithFormat
:
HERO_SOUND_DESC_URL
,pathName,fileName];
NSURL
*url = [
NSURL
URLWithString
:[string
stringByAddingPercentEscapesUsingEncoding
:
NSUTF8StringEncoding
]];
NSURLRequest
*request = [
NSURLRequest
requestWithURL
:url];
AFHTTPRequestOperation
*operation = [[
AFHTTPRequestOperation
alloc
]
initWithRequest
:request];
operation.
inputStream
= [
NSInputStream
inputStreamWithURL
:url];
operation.
outputStream
= [
NSOutputStream
outputStreamToFileAtPath
:file
append
:
NO
];
[operation
setCompletionBlockWithSuccess
:^(
AFHTTPRequestOperation
*operation,
id
responseObject) {
NSLog
(
@"
下载成功
"
);
[
_tableview
reloadData
];
}
failure
:^(
AFHTTPRequestOperation
*operation,
NSError
*error) {
NSLog
(
@"
下载失败
"
);
}];
[operation start];
//在停止滑动的时候将scrollview的缩放变为1倍
-(
void
)scrollViewDidEndDecelerating:(
UIScrollView
*)scrollView
{
_pageIndex = scrollView.contentOffset.x/SCREEN_WIDTH;
for
(
UIScrollView
*scrollview
in
scrollView.
subviews
)
{
if
([scrollview
isKindOfClass
:[
UIScrollView
class
]]) {
[scrollview setZoomScale:1.0];
}
}
HeroSkin
*skin = [
_heroskin
objectAtIndex
:
_pageIndex
];
_namelabel
.
text
= skin.
name
;
_pricelabel
.
text
= skin.
price
;
_pagelabel
.
text
= [
NSString
stringWithFormat
:
@"%ld of %lu"
,
_pageIndex
+
1
,(
unsigned
long
)
_heroskin
.
count
];
NSLog
(
@"%ld"
,(
long
)
_pageIndex
);
}
//图片摇动
-(
void
)ImageShake
{
CABasicAnimation
*basic = [
CABasicAnimation
animationWithKeyPath
:
@"transform.rotation.z"
];
basic.
fromValue
= [
NSNumber
numberWithFloat
:-
M_PI
/
16
];
basic.
toValue
= [
NSNumber
numberWithFloat
:
M_PI
/
16
];
basic.
duration
=
0.1
;
basic.
repeatCount
=
3
;
[imageview.layer addAnimation:basic forKey:@"animateLayer"];
//震动一次
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
//检測motion
-(
void
)motionEnded:(
UIEventSubtype
)motion withEvent:(
UIEvent
*)event
{
if
(motion ==
UIEventSubtypeMotionShake
) {
[
self
ImageShake
];
[
player
play
];
}
}
//计算string字符串的frame大小
-(
CGSize
)getStringRect:(
NSString
*)str
{
if
(str.
length
<
1
) {
return
CGSizeMake
(
0
,
0
);
}
CGSize
size;
NSAttributedString
*string = [[
NSAttributedString
alloc
]
initWithString
:str];
// NSDictionary *attribute= @{NSFontAttributeName:@12};
size = [string
boundingRectWithSize
:
CGSizeMake
(
280
,
500
)
options
:
NSStringDrawingTruncatesLastVisibleLine
|
NSStringDrawingUsesLineFragmentOrigin
|
NSStringDrawingUsesFontLeading
context
:
nil
].
size
;
return
size;
}
-(
CGFloat
)caculateLabelHeightWith:(
float
)fontsize String:(
NSString
*)str
{
UIFont
*font = [
UIFont
systemFontOfSize
:fontsize];
CGSize
size =
CGSizeMake
(
300
,
700
);
CGSize
descriptionSize = [str
sizeWithFont
:font
constrainedToSize
:size
lineBreakMode
:
NSLineBreakByWordWrapping
];
return
descriptionSize.
height
;
}