बाइनरी ऑपरेटर '|' दो UIViewAutoresizing ऑपरेंड पर लागू नहीं किया जा सकता है


193

स्विफ्ट 2.0 में यह त्रुटि हो रही है।

बाइनरी ऑपरेटर '|' दो UIViewAutoresizing ऑपरेंड पर लागू नहीं किया जा सकता है

यहाँ कोड है:

let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 568))
addSubview(view)
view.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight

किसी भी विचार समस्या क्या हो सकती है? यहां छवि विवरण दर्ज करें


जवाबों:


457

OptionSetTypeस्विफ्ट 2.x के लिए एक अद्यतन वाक्य रचना और स्विफ्ट 3.x के लिए एक और अद्यतन मिल गया

स्विफ्ट 3.x

view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

स्विफ्ट 2.x

view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

30

यह स्विफ्ट 1.2 और 2 के बीच अंतर हैं:

// swift 1.2
view.autoresizingMask = .FlexibleWidth | .FlexibleTopMargin

// swift 2
view.autoresizingMask = [.FlexibleWidth, .FlexibleTopMargin]

6

Xcode7-b6 के साथ प्रयास करें:

view.autoresizingMask = UIViewAutoresizing.FlexibleWidth.union(UIViewAutoresizing.FlexibleHeight)

5

के लिए Swift 3 Xcode 8 b1:

view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

@Pushpa: जिज्ञासु, मेरे जवाब के सामने "For" शब्द जोड़ने के अलावा, क्या आपने कुछ और संपादित किया / बदला जिसे मैं नहीं देख सकता? धन्यवाद
TheGeezer

2
हां, कोड ब्लॉक के अंदर कोड डाला गया है :) और हां यह उत्तर पहले से ही स्विफ्ट 2 के साथ पोस्ट किया गया है
पुष्पा वाई


-1

Xcode 7.2 के साथ इस कोड स्विफ्ट 2 का उपयोग करें

self.view.autoresizingMask = [.FlexibleRightMargin, .FlexibleLeftMargin, .FlexibleBottomMargin, .FlexibleTopMargin]
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.