Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
dz_TZImagePickerController
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shuijing
dz_TZImagePickerController
Commits
3f2db868
Commit
3f2db868
authored
Jun 03, 2018
by
tanzhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化asset选中后获取大图的方法,使其request可取消
parent
b34a83bf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
11 deletions
+51
-11
TZImagePickerController/TZImagePickerController/TZAssetCell.m
...agePickerController/TZImagePickerController/TZAssetCell.m
+20
-11
TZImagePickerController/TZImagePickerController/TZImageManager.h
...PickerController/TZImagePickerController/TZImageManager.h
+1
-0
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+30
-0
No files found.
TZImagePickerController/TZImagePickerController/TZAssetCell.m
View file @
3f2db868
...
@@ -76,7 +76,9 @@
...
@@ -76,7 +76,9 @@
}
}
// 如果用户选中了该图片,提前获取一下大图
// 如果用户选中了该图片,提前获取一下大图
if
(
model
.
isSelected
)
{
if
(
model
.
isSelected
)
{
[
self
fetchBigImage
];
[
self
requestBigImage
];
}
else
{
[
self
cancelBigImageRequest
];
}
}
if
(
model
.
needOscillatoryAnimation
)
{
if
(
model
.
needOscillatoryAnimation
)
{
[
UIView
showOscillatoryAnimationWithLayer
:
self
.
selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
[
UIView
showOscillatoryAnimationWithLayer
:
self
.
selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
...
@@ -141,12 +143,9 @@
...
@@ -141,12 +143,9 @@
[
UIView
showOscillatoryAnimationWithLayer
:
_selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
[
UIView
showOscillatoryAnimationWithLayer
:
_selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
}
}
// 用户选中了该图片,提前获取一下大图
// 用户选中了该图片,提前获取一下大图
[
self
fetch
BigImage
];
[
self
request
BigImage
];
}
else
{
// 取消选中,取消大图的获取
}
else
{
// 取消选中,取消大图的获取
if
(
_bigImageRequestID
&&
_progressView
)
{
[
self
cancelBigImageRequest
];
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
_bigImageRequestID
];
[
self
hideProgressView
];
}
}
}
}
}
...
@@ -155,13 +154,13 @@
...
@@ -155,13 +154,13 @@
self
.
imageView
.
alpha
=
1
.
0
;
self
.
imageView
.
alpha
=
1
.
0
;
}
}
-
(
void
)
fetch
BigImage
{
-
(
void
)
request
BigImage
{
_bigImageRequestID
=
[[
TZImageManager
manager
]
getPhotoWithAsset
:
_model
.
asset
completion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
_bigImageRequestID
=
[[
TZImageManager
manager
]
requestImageDataForAsset
:
_model
.
asset
completion
:
^
(
NSData
*
imageData
,
NSString
*
dataUTI
,
UIImageOrientation
orientation
,
NSDictionary
*
info
)
{
if
(
self
->
_
progressView
)
{
if
(
self
.
progressView
)
{
[
self
hideProgressView
];
[
self
hideProgressView
];
}
}
}
progressHandler
:^
(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
)
{
}
progressHandler
:^
(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
)
{
if
(
self
->
_
model
.
isSelected
)
{
if
(
self
.
model
.
isSelected
)
{
progress
=
progress
>
0
.
02
?
progress
:
0
.
02
;;
progress
=
progress
>
0
.
02
?
progress
:
0
.
02
;;
self
.
progressView
.
progress
=
progress
;
self
.
progressView
.
progress
=
progress
;
self
.
progressView
.
hidden
=
NO
;
self
.
progressView
.
hidden
=
NO
;
...
@@ -172,8 +171,18 @@
...
@@ -172,8 +171,18 @@
}
else
{
}
else
{
*
stop
=
YES
;
*
stop
=
YES
;
[
UIApplication
sharedApplication
].
networkActivityIndicatorVisible
=
NO
;
[
UIApplication
sharedApplication
].
networkActivityIndicatorVisible
=
NO
;
[
self
cancelBigImageRequest
];
}
}];
}
-
(
void
)
cancelBigImageRequest
{
if
(
_bigImageRequestID
)
{
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
_bigImageRequestID
];
}
if
(
_progressView
)
{
[
self
hideProgressView
];
}
}
}
networkAccessAllowed
:
YES
];
}
}
#pragma mark - Lazy load
#pragma mark - Lazy load
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.h
View file @
3f2db868
...
@@ -65,6 +65,7 @@
...
@@ -65,6 +65,7 @@
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
asset
photoWidth
:(
CGFloat
)
photoWidth
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
asset
photoWidth
:(
CGFloat
)
photoWidth
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:(
BOOL
)
networkAccessAllowed
;
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:(
BOOL
)
networkAccessAllowed
;
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
asset
photoWidth
:(
CGFloat
)
photoWidth
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:(
BOOL
)
networkAccessAllowed
;
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
asset
photoWidth
:(
CGFloat
)
photoWidth
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:(
BOOL
)
networkAccessAllowed
;
-
(
int32_t
)
requestImageDataForAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSData
*
imageData
,
NSString
*
dataUTI
,
UIImageOrientation
orientation
,
NSDictionary
*
info
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
;
/// Get full Image 获取原图
/// Get full Image 获取原图
/// 如下两个方法completion一般会调多次,一般会先返回缩略图,再返回原图(详见方法内部使用的系统API的说明),如果info[PHImageResultIsDegradedKey] 为 YES,则表明当前返回的是缩略图,否则是原图。
/// 如下两个方法completion一般会调多次,一般会先返回缩略图,再返回原图(详见方法内部使用的系统API的说明),如果info[PHImageResultIsDegradedKey] 为 YES,则表明当前返回的是缩略图,否则是原图。
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
3f2db868
...
@@ -474,6 +474,36 @@ static dispatch_once_t onceToken;
...
@@ -474,6 +474,36 @@ static dispatch_once_t onceToken;
return
[
self
getPhotoWithAsset
:
asset
photoWidth
:
fullScreenWidth
completion
:
completion
progressHandler
:
progressHandler
networkAccessAllowed
:
networkAccessAllowed
];
return
[
self
getPhotoWithAsset
:
asset
photoWidth
:
fullScreenWidth
completion
:
completion
progressHandler
:
progressHandler
networkAccessAllowed
:
networkAccessAllowed
];
}
}
-
(
int32_t
)
requestImageDataForAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSData
*
imageData
,
NSString
*
dataUTI
,
UIImageOrientation
orientation
,
NSDictionary
*
info
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
{
if
([
asset
isKindOfClass
:[
PHAsset
class
]])
{
PHImageRequestOptions
*
options
=
[[
PHImageRequestOptions
alloc
]
init
];
options
.
progressHandler
=
^
(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
if
(
progressHandler
)
{
progressHandler
(
progress
,
error
,
stop
,
info
);
}
});
};
options
.
networkAccessAllowed
=
YES
;
options
.
resizeMode
=
PHImageRequestOptionsResizeModeFast
;
int32_t
imageRequestID
=
[[
PHImageManager
defaultManager
]
requestImageDataForAsset
:
asset
options
:
options
resultHandler
:^
(
NSData
*
imageData
,
NSString
*
dataUTI
,
UIImageOrientation
orientation
,
NSDictionary
*
info
)
{
if
(
completion
)
completion
(
imageData
,
dataUTI
,
orientation
,
info
);
}];
return
imageRequestID
;
}
else
if
([
asset
isKindOfClass
:[
ALAsset
class
]])
{
ALAsset
*
alAsset
=
(
ALAsset
*
)
asset
;
dispatch_async
(
dispatch_get_global_queue
(
0
,
0
),
^
{
ALAssetRepresentation
*
assetRep
=
[
alAsset
defaultRepresentation
];
CGImageRef
fullScrennImageRef
=
[
assetRep
fullScreenImage
];
UIImage
*
fullScrennImage
=
[
UIImage
imageWithCGImage
:
fullScrennImageRef
scale
:
2
.
0
orientation
:
UIImageOrientationUp
];
dispatch_async
(
dispatch_get_main_queue
(),
^
{
if
(
completion
)
completion
(
UIImageJPEGRepresentation
(
fullScrennImage
,
0
.
83
),
nil
,
UIImageOrientationUp
,
nil
);
});
});
}
return
0
;
}
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
asset
photoWidth
:(
CGFloat
)
photoWidth
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:(
BOOL
)
networkAccessAllowed
{
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
asset
photoWidth
:(
CGFloat
)
photoWidth
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:(
BOOL
)
networkAccessAllowed
{
if
([
asset
isKindOfClass
:[
PHAsset
class
]])
{
if
([
asset
isKindOfClass
:[
PHAsset
class
]])
{
CGSize
imageSize
;
CGSize
imageSize
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment