Determine if two controls overlap on the same window

Source: Internet
Author: User

Determine if two controls overlap on the same window

Write classification to UIView-(BOOL) Intersectwithview: (UIView *) view;-(BOOL) Intersectwithview: (UIView *) view{    UIWindow *window = [UIApplication Sharedapplication].keywindow;    CGRect selfrect = [self convertRect:self.bounds toview:window];    CGRect viewrect = [view ConvertRect:view.bounds Toview:window];    Return Cgrectintersectsrect (Selfrect, viewrect);}

Add a higher-level uiwindow to let ScrollView scroll to the top when you click the status bar

. h file #import <Foundation/Foundation.h> @interface jgtopwindow:nsobject+ (void) show; @end//.m file #import " JGTopWindow.h "@implementation jgtopwindowstatic uiwindow *window_;+ (void) show{Dispatch_after (Dispatch_time ( Dispatch_time_now, (int64_t) (0.25 * nsec_per_sec)), Dispatch_get_main_queue (), ^{window_ = [[UIWindow alloc] init]        ;        Window_.frame = [UIApplication sharedapplication].statusbarframe;        The window is displayed by default black Window_.backgroundcolor = [Uicolor Clearcolor]; Uiwindowlevelalert > Uiwindowlevelstatusbar > Uiwindowlevelnormal//window default level is Uiwindowlevelnormal, lowest level, placed on the bottom layer        , click Gesture is intercepted, can not be heard window_.windowlevel = Uiwindowlevelalert;        The default is hidden Window_.hidden = NO; [Window_ Addgesturerecognizer:[[uitapgesturerecognizer alloc] initwithtarget:self action: @selector (Topwindowclick)    ]]; });}        + (void) topwindowclick{//main window UIWindow *window = [UIApplication Sharedapplication].keywindow; Find all ScrollView in the main window [sElf Findscrollviewsinview:window];} /** * Find all ScrollView */+ (void) Findscrollviewsinview in view: (UIView *) view{//Use recursion to find all child controls for (UIView *subview in    View.subviews) {[Self findscrollviewsinview:subview]; } if (![        View Iskindofclass:[uiscrollview class]]) return; Determine if there is overlap with window if (![    View Intersectwithview:[uiapplication Sharedapplication].keywindow]) return;    CGRect windowrect = [UIApplication sharedapplication].keywindow.bounds;    CGRect viewrect = [view ConvertRect:view.bounds Toview:nil]; does not overlap with window//if (!        Cgrectintersectsrect (Windowrect, Viewrect)) return;    If it is scrollView uiscrollview *scrollview = (Uiscrollview *) view;    Modify offset Cgpoint offset = scrollview.contentoffset;    Offset.y =-ScrollView.contentInset.top;        [ScrollView Setcontentoffset:offset Animated:yes]; [ScrollView scrollrecttovisible:cgrectmake (0, 0, 1, 1) animated:yes];} @end

Determine if two controls overlap on the same window

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.