iOS screen notifications

Source: Internet
Author: User

    1. A notification is sent when the screen is switched. Just register a notification:

[Java]View Plaincopy
  1. [[Nsnotificationcenter Defaultcenter] Addobserver:self
  2. Selector:@selector (dorotateaction:)
  3. Name:uideviceorientationdidchangenotification
  4. Object:nil];

Then do the operation in the method:

[Java]View Plaincopy
    1. -(void)  dorotateaction: (nsnotification  *)  notification{  
    2.     if  ( [[uidevice currentdevice] orientation]==uiinterfaceorientationportrait   
    3.         | |  [[uidevice currentdevice] orientation]==uiinterfaceorientationportraitupsidedown)  {    
    4.         nslog (@
    5.     }else{    
    6.         nslog (@
    7.     }  
    8. }  

If you want to make a switch screen in the portal file, you can determine the orientation of the status bar:

[Java]View Plaincopy
    1. ////////////////////////////////////
    2. Notification delegate status bar has changed, into the screen operation
    3. -(void) Application: (UIApplication *) application didchangestatusbarorientation: (uiinterfaceorientation) oldstatusbarorientation{
    4. //clear background to prevent image residue from last screen turn
    5. [ImageView Setbackgroundcolor:[uicolor Clearcolor];
    6. //The following is a 4-direction switch between the horizontal and vertical screen, pay attention to turn the screen, regardless of which screen to turn. The starting coordinates are calculated from the starting point of the portrait direction (0,0) .
    7. if ([[[Uidevice Currentdevice] orientation]==uiinterfaceorientationportrait) {
    8. NSLog (@">>>portrait"); //home key in the next
    9. ImageView = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 768, 44)];
    10. Imageview.backgroundcolor = [Uicolor Redcolor];
    11. [_window Addsubview:imageview];
    12. }Else if ([[[Uidevice Currentdevice] orientation]==uiinterfaceorientationportraitupsidedown) {
    13. NSLog (@">>>portraitupsidedown"); //home key on the
    14. ImageView = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 960, 768, 44)];
    15. Imageview.backgroundcolor = [Uicolor Redcolor];
    16. [_window Addsubview:imageview];
    17. }Else if ([[[Uidevice Currentdevice] orientation]==uiinterfaceorientationlandscapeleft) {
    18. NSLog (@">>>landscapeleft"); //home key in left
    19. ImageView = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 1024)];
    20. Imageview.backgroundcolor = [Uicolor Redcolor];
    21. [_window Addsubview:imageview];
    22. }
    23. Else if ([[Uidevice Currentdevice] orientation]==uiinterfaceorientationlandscaperight) {
    24. NSLog (@">>>landscaperight"); //home key on right
    25. ImageView = [[Uiimageview alloc] Initwithframe:cgrectmake (704, 0, 1024)];
    26. Imageview.backgroundcolor = [Uicolor Redcolor];
    27. [_window Addsubview:imageview];
    28. }
    29. }

iOS screen notifications

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.