से ऊपर फ़्लोटिंग देखें आईओएस पर यह संभव है कि एक दृश्य हमेशा अन्य सभी विचारों से ऊपर तैरता है। मैं यह पूछता हूं क्योंकि मैं जो हासिल करना चाहता हूं वह एक दृश्य है जो व्यू कंट्रोलर के ऊपर तैरता है, और उसके बाद एक मॉडल व्यू कंट्रोलर स्लाइड करता है, जबकि उस विशेष दृश्य को अभी भी उस मॉडल व्यू कंट्रोलर पर तैर रहा है (उम्मीद है कि मैं जो कहने की कोशिश कर रहा हूं)।सभी व्यू कंट्रोलर
5
A
उत्तर
8
वहाँ है। आप अपना दृश्य मुख्य window
पर जोड़ सकते हैं और जब आपको करना होगा तो इसे सामने लाएं।
निम्नलिखित कोड में माना जाता है कि _viewConroller
और _anotherView
ऐपडिलेगेट के मजबूत गुण हैं - कॉन्फ़िगरेशन निश्चित रूप से भिन्न हो सकता है।
यह कोड स्क्रीन के ऊपरी बाएं कोने में छोटे नीले वर्ग को जोड़ देगा।
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
_anotherView = [[UIView alloc] initWithFrame: CGRectMake (0.0,0.0,20.0,20.0)];
[anotherView setBackgroundColor: [UIColor blueColor]];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self.window addSubView: _anotherView];
[self.window bringSubViewToFront: _anotherView]; //not really needed here but it doesn't do any harm
return YES;
}
3
यदि आप स्टोरीबोर्ड और autolayout (द्वारा पहले उत्तर प्रेरित)
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *_vc = [sb instantiateViewControllerWithIdentifier:@"FloatingController"];
_anotherView = _vc.view;
[_anotherView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.window addSubview: _anotherView];
[[VLBConstraintsGenerator sharedInstance] setWidth:200 forView:_anotherView inSuperView:_window];
[[VLBConstraintsGenerator sharedInstance] setHeight:200 forView:_anotherView inSuperView:_window];
[[VLBConstraintsGenerator sharedInstance] setLeading:0 forView:_anotherView inSuperView:_window];
[_anotherView setBackgroundColor:[UIColor grayColor]];
[[_anotherView layer] setBorderWidth:1];
[[_anotherView layer] setBorderColor:[UIColor yellowColor].CGColor];
[self.window makeKeyAndVisible];
[self.window bringSubviewToFront:_anotherView]; //not really needed here but it doesn't do any harm
तुम सब करने की जरूरत है के साथ मुख्य स्टोरीबोर्ड में एक दृश्य नियंत्रक खींचें करने के लिए है का उपयोग कर रहे निम्न कर सकते हैं FloatingController एक स्टोरीबोर्ड आईडी के रूप में
अतिरिक्त तरीके
-(void)setWidth:(CGFloat)theWidth forView:(UIView *)theView inSuperView:(UIView *)theSuperView
{
assert([theSuperView isEqual:theView.superview]);
NSLayoutConstraint *cn = [NSLayoutConstraint constraintWithItem:theView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:theWidth];
// [cn setPriority:999];//make it variable according to the orientation
[theSuperView addConstraint:cn];
}
-(void)setHeight:(CGFloat)theHeight forView:(UIView *)theView inSuperView:(UIView *)theSuperView
{
assert([theSuperView isEqual:theView.superview]);
NSLayoutConstraint *cn = [NSLayoutConstraint constraintWithItem:theView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:theHeight];
[theSuperView addConstraint:cn];
}
-(void)setLeading:(CGFloat)theLeading forView:(UIView *)theView inSuperView:(UIView *)theSuperView
{
assert([theSuperView isEqual:theView.superview]);
NSLayoutConstraint *cn = [NSLayoutConstraint constraintWithItem:theView
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:theSuperView
attribute:NSLayoutAttributeLeading
multiplier:1
constant:theLeading];
[theSuperView addConstraint:cn];
}
ठीक है, क्या आप स्टोरीबोर्डिंग का उपयोग करते समय भी यह काम करेंगे? – thvanarkel
मैं इसे कमजोर करना चाहिए, लेकिन मैंने इसे आजमाया नहीं। यह संभव है कि आपको _anotherViewToFront लाने के लिए एक विधि बनाना होगा और इसे देखने के बाद कॉल करें नियंत्रक स्थान बदलते हैं। –