iOS PHLivePhotoView

An PHLivePhotoViewobject is a view that displays a Live Photo.

I. Overview

After acquiring an PHLivePhotoobject, use a Live Photo view to display the photo and control its actions and sound content. In iOS and tvOS, you can obtain Live Photo objects from the photo library using UIImagePickerControllereither the PHAsset and PHImageManager classes or by creating an asset that exports from the photo library. On macOS, the Live Photo object is only available when editing the content of the Live Photo while running a photo editing extension in the Photos app. - View PHContentEditingInputclass to get Live Photo content in editing session.

Note
For information on how to integrate Live Photos with your app's user experience, see Live Photos in the iOS Human Interface Guidelines .

By default, a Live Photo view uses its own gesture recognizers to allow users to play motion and sound content in a Live Photo, with the same interactions and visual effects as in the Photos app. To customize this gesture recognizer—for example, to install it in a different view to properly handle your app's view-level events—use playbackGestureRecognizerproperties.

Typically, an application does not need to directly control Live Photo playback. In some cases, it can use a short animation to indicate to the user that the image is a Live Photo. To do this, use - (void)startPlaybackWithStyle:(PHLivePhotoViewPlaybackStyle)playbackStyle;a method and pass in PHLivePhotoViewPlaybackStyleHinta type parameter.

Tips
To display Live Photo content on a web page, please use the LivePhotosKit JS framework.

2. Content

1. Choose a Live Photo to display

@property(readwrite, nonatomic, strong) PHLivePhoto *livePhoto;

The Live Photo shown in the view.

2. Play management

@property(readonly, nonatomic, strong) UIGestureRecognizer *playbackGestureRecognizer;

A point gesture recognizer that controls Live Photo playback in the view.

The Live Photo view automatically creates and installs this gesture recognizer. Use this property to customize the gesture recognizer's behavior. For example, you can use it in a delegate method to influence how it interacts with other gesture recognizers, or install it in other views to ensure proper event handling in your application's view hierarchy.

@property(readwrite, nonatomic, assign, getter=isMuted) BOOL muted;

Whether to forbid playing the audio content of Live Photo.

The default value of this property NOindicates that the view will play audio content with the Live Photo's actions. A value of this property changes YESto indicate that the action will be played but no audio will be played.

@property(readwrite, nonatomic, assign) float audioVolume;

The volume of the sound when the action content of the Live Photo is played.

The value of this property must be between 0.0 and 1.0. A value of 1.0 (the default) will play the Live Photo's audio at maximum volume (relative to the maximum volume of the system volume). A value of 0.0 is equivalent to setting mutedthe property to YES.

3. Respond to playback events

@property(readwrite, nonatomic, weak) id delegate;

The object to be notified when the Live Photo starts playing or ends playing.

4. Play Live Photo content manually

- (void)startPlaybackWithStyle:(PHLivePhotoViewPlaybackStyle)playbackStyle;

Start playing the content of the Live Photo in the view.

Use playbackStylethe properties to choose whether to play the entire motion and sound content of the Live Photo or just a brief part.

Typically, an app does not need to directly control playback, since a Live Photo view provides interactive playback controls. Use this method when there is no appropriate interactive playback -- for example, a short animation indicating that a view's content is a Live Photo.

PHLivePhotoViewPlaybackStyle

typedef NS_ENUM(NSInteger, PHLivePhotoViewPlaybackStyle) {
    
    
    PHLivePhotoViewPlaybackStyleUndefined = 0, // 这个值对用户无效
    PHLivePhotoViewPlaybackStyleFull, // 播放Live Photo的整个动作和声音内容,包括开始和结束的过渡效果。
    PHLivePhotoViewPlaybackStyleHint, // 只播放Live Photo的一段简短的动作内容,没有声音。
} PHOTOS_ENUM_AVAILABLE_IOS_TVOS(9_1, 10_0);

- (void)stopPlayback;

Ends the Live Photo content playing in the view.

5. Get the user interface icon of Live Photo

+ (UIImage *)livePhotoBadgeImageWithOptions:(PHLivePhotoBadgeOptions)badgeOptions;

Returns the picture image for the given Live Photo semantic option.

Use this method to populate the Live Photo interface element for the user to get the icon image. For example, you could use this method to obtain an icon from a custom asset browser interface to indicate that the asset is a Live Photo instead of a normal static image, or to indicate that the user chooses to share a content with or without motion and sound Live Photo.

By default, this method returns a solid color image suitable for use as a stencil image, which you can color and display against a specific background. (Use UIImagethe class to create template images.) When you plan to overlay icons with animated Live Photo content, add PHLivePhotoBadgeOptionsOverContentthe option to get an image (not available for template use) to provide additional background contrast.

typedef NS_OPTIONS(NSUInteger, PHLivePhotoBadgeOptions) {
    
    
    PHLivePhotoBadgeOptionsOverContent  = 1 << 0, // 返回一个标示不选择动作和声音内容的图标
    PHLivePhotoBadgeOptionsLiveOff      = 1 << 1, // 返回一个标示Live Photo的变量图标
} PHOTOS_ENUM_AVAILABLE_IOS_TVOS(9_1, 10_0);

@property(readonly, nonatomic, strong) NSView *livePhotoBadgeView;

A view showing the status of a Live Photo.

PHLivePhotoView uses this subview to display icons that indicate the presence or status of Live Photo content. Photos manages badge viewthe content displayed on it, so you don't need to do anything with the view's content - instead, this property provides access badge viewso you can change its display hierarchy in your view if needed. For example, if you're scroll viewshowing a Live Photo view in a , you can move this badge viewso that scroll viewit stays in place when you swipe.

Je suppose que tu aimes

Origine blog.csdn.net/chennai1101/article/details/129992076
conseillé
Classement