在屏幕特定位置点击隐藏子窗口

#import "ViewController.h"
#import "MusicListView.h"

@interface ViewController ()

// 列表子窗口
@property (nonatomic, strong) MusicListView* listView;

// 进度条控件
@property (strong, nonatomic) IBOutlet UIImageView *progressImageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    // other codes
    // ...
}

// other codes
// ...
#pragma mark --TOUCH事件

// 触摸事件
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    
    // 获取触摸点
    CGPoint clickPoint = [touch locationInView:self.view];
    
    // 判断是否需要隐藏:只有当列表子窗口处于显示状态才处理隐藏
    if (_listView.alpha == 1)
    {
        // 只有在特定位置或区域才处理触摸事件
        if (clickPoint.y < _progressImageView.frame.origin.y)
        {
            _listView.alpha = 0;
        }
    }
}


@end

你可能感兴趣的:(在屏幕特定位置点击隐藏子窗口)