Key Window提示View

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface AddSuccessView : UIView
@property (weak, nonatomic) IBOutlet UIImageView *centerView;
@property (weak, nonatomic) IBOutlet UIButton *closeBtn;
@property (weak, nonatomic) IBOutlet UIButton *knowBtn;
@property (weak, nonatomic) IBOutlet UILabel *alertTitle;

+(void)showAddSuccessView;
+(void)hideAddSuccessView;
@end

NS_ASSUME_NONNULL_END
AddSuccessView.h
//
//  AddSuccessView.m
//  WaterProofer
//
//  Created by ios on 2019/9/17.
//  Copyright © 2019年 WaterProofer. All rights reserved.
//

#import "AddSuccessView.h"

@implementation AddSuccessView
+(void)showAddSuccessView{
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    AddSuccessView *sView = [AddSuccessView customerView];
    [keyWindow addSubview:sView];
    [UIView animateWithDuration:0.3 animations:^{
        sView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    } completion:^(BOOL finished) {
        
    }];
}
+(void)hideAddSuccessView{
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    NSEnumerator *subviewsEnum = [keyWindow.subviews reverseObjectEnumerator];
    for (UIView *subview in subviewsEnum) {
        if ([subview isKindOfClass:[AddSuccessView class]]) {
            [UIView animateWithDuration:0.3 animations:^{
                subview.frame = CGRectMake(0,SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
            } completion:^(BOOL finished) {
                [subview removeFromSuperview];
            }];
        }
    }
}
+(instancetype)customerView
{
    return [[[NSBundle mainBundle] loadNibNamed:@"AddSuccessView" owner:self options:nil] firstObject];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    _knowBtn.backgroundColor = ColorHex_D9261C;
    _knowBtn.layer.cornerRadius = 20;
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.85];
}

- (IBAction)knowBtnClick:(UIButton *)sender {
     [AddSuccessView hideAddSuccessView];
}
- (IBAction)closeBtnClick:(UIButton *)sender {
    [AddSuccessView hideAddSuccessView];
}

@end
AddSuccessView.h
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
    <device id="retina4_7" orientation="portrait">
        <adaptation id="fullscreen"/>
    </device>
    <dependencies>
        <deployment identifier="iOS"/>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <objects>
        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
        <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
        <view contentMode="scaleToFill" id="iN0-l3-epB" customClass="AddSuccessView">
            <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
            <subviews>
                <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="hire_wait_sure" translatesAutoresizingMaskIntoConstraints="NO" id="PPP-eC-x5D">
                    <rect key="frame" x="52" y="210" width="271" height="267"/>
                    <constraints>
                        <constraint firstAttribute="width" secondItem="PPP-eC-x5D" secondAttribute="height" multiplier="64:63" id="OoH-sF-Eoj"/>
                    </constraints>
                </imageView>
                <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jCo-DA-7yP">
                    <rect key="frame" x="85" y="416" width="205" height="41"/>
                    <color key="backgroundColor" red="0.78431372549019607" green="0.22352941176470589" blue="0.16862745098039217" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                    <constraints>
                        <constraint firstAttribute="width" secondItem="jCo-DA-7yP" secondAttribute="height" multiplier="5:1" id="vYG-RA-4F6"/>
                    </constraints>
                    <state key="normal" title="我知道了">
                        <color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                    </state>
                    <connections>
                        <action selector="knowBtnClick:" destination="iN0-l3-epB" eventType="touchUpInside" id="qa1-TT-oFG"/>
                    </connections>
                </button>
                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="已添加,等待对方确认" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Lac-r3-eks">
                    <rect key="frame" x="112.5" y="370" width="150" height="21"/>
                    <fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="15"/>
                    <nil key="textColor"/>
                    <nil key="highlightedColor"/>
                </label>
                <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="u5H-eg-OCY">
                    <rect key="frame" x="293" y="215" width="25" height="25"/>
                    <constraints>
                        <constraint firstAttribute="width" constant="25" id="4eV-eL-lzj"/>
                        <constraint firstAttribute="height" constant="25" id="NJa-69-RIH"/>
                    </constraints>
                    <state key="normal" image="hire_close_icon"/>
                    <connections>
                        <action selector="closeBtnClick:" destination="iN0-l3-epB" eventType="touchUpInside" id="fww-3H-wps"/>
                    </connections>
                </button>
            </subviews>
            <constraints>
                <constraint firstItem="jCo-DA-7yP" firstAttribute="top" secondItem="Lac-r3-eks" secondAttribute="bottom" constant="25" id="9cP-Jv-qTo"/>
                <constraint firstItem="PPP-eC-x5D" firstAttribute="centerY" secondItem="vUN-kp-3ea" secondAttribute="centerY" id="RDH-4b-Ree"/>
                <constraint firstItem="PPP-eC-x5D" firstAttribute="centerX" secondItem="vUN-kp-3ea" secondAttribute="centerX" id="Rfo-Dx-EmO"/>
                <constraint firstItem="u5H-eg-OCY" firstAttribute="top" secondItem="PPP-eC-x5D" secondAttribute="top" constant="5" id="T19-gk-vCz"/>
                <constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="jCo-DA-7yP" secondAttribute="trailing" constant="85" id="Ts8-La-rZG"/>
                <constraint firstItem="u5H-eg-OCY" firstAttribute="trailing" secondItem="PPP-eC-x5D" secondAttribute="trailing" constant="-5" id="eLq-25-ON7"/>
                <constraint firstAttribute="trailing" secondItem="PPP-eC-x5D" secondAttribute="trailing" constant="52" id="ebn-ar-otC"/>
                <constraint firstItem="Lac-r3-eks" firstAttribute="centerX" secondItem="jCo-DA-7yP" secondAttribute="centerX" id="lF7-4h-ZeK"/>
                <constraint firstItem="jCo-DA-7yP" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="85" id="r1K-ni-bVr"/>
                <constraint firstItem="jCo-DA-7yP" firstAttribute="bottom" secondItem="PPP-eC-x5D" secondAttribute="bottom" constant="-20" id="zOU-gf-ofC"/>
                <constraint firstItem="PPP-eC-x5D" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="52" id="zPK-ao-syP"/>
            </constraints>
            <viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
            <connections>
                <outlet property="alertTitle" destination="Lac-r3-eks" id="zPp-4H-4mY"/>
                <outlet property="centerView" destination="PPP-eC-x5D" id="H0F-AS-vCa"/>
                <outlet property="closeBtn" destination="u5H-eg-OCY" id="Oy6-3b-Cci"/>
                <outlet property="knowBtn" destination="jCo-DA-7yP" id="Pif-Th-RdY"/>
            </connections>
        </view>
    </objects>
    <resources>
        <image name="hire_close_icon" width="54" height="54"/>
        <image name="hire_wait_sure" width="512" height="504"/>
    </resources>
</document>
AddSuccessView.xib

猜你喜欢

转载自www.cnblogs.com/kingstudy/p/11538245.html
key