UIViewController+BBA3DTouch.h 5.11 KB
//
//  UIViewController+BBA3DTouch.h
//  BBA3DTouch
//
//  Created by hyman on 2017/3/31.
//  Copyright © 2017年 hyman. All rights reserved.
//

// MIT License
//
// Copyright (c) 2017 hyman (https://github.com/Hyman00/BBA3DTouch)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#import <UIKit/UIKit.h>
#import "BBA3DTouchConfig.h"

typedef NS_ENUM(NSUInteger, BBA3DViewControllerAppear) {
    BBA3DViewControllerAppear_None = 0,
    BBA3DViewControllerAppear_WillAppear,
    BBA3DViewControllerAppear_DidAppear,
    BBA3DViewControllerAppear_WillDisappear,
    BBA3DViewControllerAppear_DidDisappear
};

typedef NS_ENUM(NSUInteger, BBA3DTouchStatus) {
    BBA3DTouchStatus_None = 0,
    BBA3DTouchStatus_Prepared,
    BBA3DTouchStatus_Previewing,
    BBA3DTouchStatus_Poped
};

typedef NS_ENUM(NSUInteger, BBA3DTouchActionStatus) {
    BBA3DTouchActionStatus_None = 0,
    BBA3DTouchActionStatus_WillPeek,
    BBA3DTouchActionStatus_DidPeek,
    BBA3DTouchActionStatus_WillPop,
    BBA3DTouchActionStatus_DidPop,
    BBA3DTouchActionStatus_Cancel
};

/**
 *  @brief 当用户在进行3D Touch相关操作时,将会发送该通知,并传递对应在那个页面进行的操作,以及当前操作的状态。
 *   即:userInfo里包括2个key-value:{BBA3DTouchActionUserInfoPageKey: 操作的页面, BBA3DTouchActionUserInfoStatusKey: 当前操作状态}
 */
extern NSString * const BBA3DTouchActionNotification;
extern NSString * const BBA3DTouchActionUserInfoPageKey;
extern NSString * const BBA3DTouchActionUserInfoStatusKey;

/**
 *  @brief  It will be called when the sourceView will peek or pop.
 *  If the block return NO, then the 3D Touch will lose efficacy. 
    (It only takes effect when status is BBA3DTouchStatus_WillPeek and BBA3DTouchStatus_WillPop)
 *
 *  @param sourceView   A source view, in a previewing view controller’s view hierarchy, responds to a forceful touch by the use
 */
typedef BOOL(^BBA3DTouchTriggerBlock) (BBA3DTouchActionStatus status, UIView *sourceView);


@interface UIViewController (BBA3DTouch) <UIViewControllerPreviewingDelegate>

@property (nonatomic, assign, readonly) BBA3DViewControllerAppear bba_appearStatus;

@property (nonatomic, assign, readonly) BBA3DTouchStatus bba_3DTouchStatus API_AVAILABLE(ios(9.0));
@property (nonatomic, assign, readonly) BBA3DTouchActionStatus bba_3DTouchActionStatus API_AVAILABLE(ios(9.0));
@property (nonatomic, copy, setter=bba_set3DTouchTriggerBlock:) BBA3DTouchTriggerBlock bba_3DTouchTriggerBlock API_AVAILABLE(ios(9.0));

/**
 *  @brief  active 3D Touch for UITableView
 *
 *  The method will automatic register 3D Touch for each cell.
 *
 *  @note
 *  Need to implement the tableView: didSelectRowAtIndexPath: method for the UITableViewDelegate
 *
 */
- (void)bba_active3DTouchTable:(UITableView *)tableView
                forNavigation:(UINavigationController *)navigation API_AVAILABLE(ios(9.0));

/**
 *  @brief  active 3D Touch for UICollectionView
 *
 *  The method will automatic register 3D Touch for each cell.
 *
 *  @note 
 *  1, Need to implement the collectionView: didSelectItemAtIndexPath: for the UICollectionViewDelegate
 *
 *  2, If the collectionView: shouldSelectItemAtIndexPath: method for the UICollectionViewDelegate return NO, at the indexPath of cell will not be registered 3D Touch;
 *
 */
- (void)bba_active3DTouchCollectionView:(UICollectionView *)collectionView
                         forNavigation:(UINavigationController *)navigation API_AVAILABLE(ios(9.0));

/**
 *  @brief  active 3D Touch for view
 *
 *  @param target     the responder of the click
 *  @param action     the action of the click
 *  @param argument   an object that is the sole argument of the action
 *
 *  @note
 *  If the view is UITableView or UICollectionView, the method will ignore target, action, argument
 */
- (void)bba_active3DTouchView:(UIView *)view
                 clickTarget:(NSObject *)target
                 clickAction:(SEL)action
                    argument:(id)argument
               forNavigation:(UINavigationController *)navigation API_AVAILABLE(ios(9.0));

- (void)bba_active3DTouchView:(UIView *)view touchConfig:(BBA3DTouchConfig *)touchConfig API_AVAILABLE(ios(9.0));

@end