2013-04-29 2 views
3
self.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleWidth; 

소스 코드는 위에 나와 있습니다. 원더 무엇이 기호 "|" 약자? 답장을 보내 주시면 답변 해 주셔서 감사합니다.)자주 사용되는 기호 "|" Objective-C에서

답변

12

요약하면 bitwise OR입니다.

비트 마스크를 생성하는 데 기본적으로 사용됩니다.

이 작업을 통해 이진수에 플래그를 결합 할 수 있습니다.

: UIViewAutoresizing 가능한 플래그는 :

enum { 
    UIViewAutoresizingNone     = 0,   // = 0b 0000 0000 = 0 
    UIViewAutoresizingFlexibleLeftMargin = 1 << 0,  // = 0b 0000 0001 = 1 
    UIViewAutoresizingFlexibleWidth  = 1 << 1,  // = 0b 0000 0010 = 2 
    UIViewAutoresizingFlexibleRightMargin = 1 << 2,  // = 0b 0000 0100 = 4 
    UIViewAutoresizingFlexibleTopMargin = 1 << 3,  // = 0b 0000 1000 = 8 
    UIViewAutoresizingFlexibleHeight  = 1 << 4,  // = 0b 0001 0000 = 16 
    UIViewAutoresizingFlexibleBottomMargin = 1 << 5  // = 0b 0010 0000 = 32 
}; 
typedef NSUInteger UIViewAutoresizing; 

성명 :

self.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleWidth; 

가 esentially 동일하다 :

self.autoresizingMask = UIViewAutoresizingFlexibleWidth; 

(피연산자가 모두 동일하기 때문에) .

에 대해 당신이 요청한다면이가 self.autoresizingMask을 설정합니다

self.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; 

:

(1<<1)|(1<<4)=(0b 0000 0010)|(0b 0001 0000)=0b 0001 0010 = 9 

비트 단위 OR 간단한 참/거짓 대수와 함께 사용 Logical OR에 의해 혼동되지 않습니다.

둘 사이에는 어떤 관계가 있습니다 (비트 식 또는 논리 식 또는 동일한 위치의 비트 사이에서 이해할 수 있음)하지만 그 정도입니다.

+2

+1 좋은 답변입니다. – Popeye

+0

@Popeye : 고마워요! –

4

| 문자는 포괄적 인 또는 비트 단위의 연산을 나타냅니다. 두 개체의 비트 문자열을 일치시키는 전제하에 작동합니다.

비트 스트링이 1101이고 다른 하나가 1001이거나 둘 중 하나가 1011을 생성하는 경우 기본적으로 현재 비트가 두 문자열에서 동일하면 1이 그 자리에 출력되고 그렇지 않으면 0이 출력됩니다.

관련 문제