码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发 获取状态栏的点击事件

时间:2016-12-27 16:04:37      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:enabled   pyc   sse   default   div   with   copy   bsp   cti   

首先我们追踪UIStatusBar的触摸事件,需要在AppDelegate里面加入以下代码

技术分享
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    CGPoint location = [[[event allTouches] anyObject] locationInView:self.window];
    CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
    if (CGRectContainsPoint(statusBarFrame, location)) {
        [self statusBarTouchedAction];
    }
}
技术分享

然后在statusBarTouchedAction方法中将显示在当前keyWindow里面的scrollView滚动到顶部

- (void)statusBarTouchedAction {

      [[DDTopWindow defaultDDTopWindow] scrollsToTop];

}

下面来看JMSUIScrollViewTool

技术分享

@interface DDTopWindow : UIView

 

+ (instancetype)defaultDDTopWindow;

 

- (void)configScrollView:(UIScrollView *)scrollView isCanTop:(BOOL)isCanTop;

 

- (void)scrollsToTop;

 

@end

 

技术分享
技术分享

#import "DDTopWindow.h"

 

static UIScrollView *scrollView_;

 

@interface DDTopWindow ()

 

@property (nonatomic, assign) BOOL isCan;

 

@end

 

@implementation DDTopWindow

 

SYNTHESIZE_SINGLETON_FOR_CLASS_ARC(DDTopWindow);

 

- (void)configScrollView:(UIScrollView *)scrollView isCanTop:(BOOL)isCanTop {

  scrollView_ = scrollView;

  self.isCan = isCanTop;

}

 

- (void)scrollsToTop {

  if (scrollView_.scrollEnabled) {

    [scrollView_ setContentOffset:CGPointMake(scrollView_.contentOffset.x, -scrollView_.contentInset.top) animated:YES];

  }

}

 

@end

 

技术分享

iOS开发 获取状态栏的点击事件

标签:enabled   pyc   sse   default   div   with   copy   bsp   cti   

原文地址:http://www.cnblogs.com/diweinan/p/6226206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!