IOS Development Notes (1)

Source: Internet
Author: User

1. Obtain the date of the current day

Nsdate * today;

Today = [nsdate date];

 

2. [[uidevice currentdevice] orientation] the following seven statuses are available for obtaining device statuses:

Uideviceorientationunknown

Uideviceorientationportrait // device oriented vertically, Home button one the button

Uideviceorientationportraitupsidedown // device oriented vertically, Home button one the top

Uideviceorientationlandscapeleft // device oriented horizontally, Home button on the right

Uideviceorientationlandscaperight // device oriented horizontally, Home button on the left

Uideviceorientationfaceup // device oriented flat, face up

Uideviceorientationfacedown // device oriented flat, face down

In the first and last states, if you perform some operations when the status changes, it is okay, this is because only four rotating states can be captured during the operation. However, if you want to do something according to the status during the operation, it will be problematic, because it is very likely that the three non-rotating states will be obtained. Solution: Remember the previous rotation status. When the obtained status is not four, use the previous normal rotation status.

- (void)applicationDidFinishLaunching:(UIApplication *)application {   [window addSubview:crateViewController.view];   [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];   [[NSNotificationCenter defaultCenter] addObserver:self      selector:@selector(orientationChanged:)      name:@"UIDeviceOrientationDidChangeNotification" object:nil];}
- (void)orientationChanged:(NSNotification *)notification{  UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];  if (UIDeviceOrientationIsPortrait(orientation) || UIDeviceOrientationIsLandscape(orientation))  {    if (!currentOrientation)    {      currentOrientation = orientation;      [self prepareScreen];    }    currentOrientation = orientation;  }  [[UIApplication sharedApplication] setStatusBarOrientation:currentOrientation animated:YES];}

3. uibutton can eat all touches events, and no penetrating method has been found yet.

Note: place a uibutton in the uiview. The size and position of the uibutton are exactly the same as that of the uiview. In this case, the touchesbegan: touchesmoved: touchesended of the uiview itself: and so on. If you have business requirements, we recommend that you use uiimageview to change the image resources through the touchesbegan and touchesenden events. In this way, the button clicking effect can also be achieved.

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.