Возможно ли на iOS, что представление всегда плавает над всеми другими видами. Я спрашиваю об этом, потому что то, что я хотел бы достичь, - это представление, которое плавает над ViewController, а затем контроллер Modal View Control, в то время как этот конкретный вид все еще плавает над этим Modal View Controller (надеюсь, что вы получите то, что я пытаюсь сказать).View over over ViewControllers
5
A
ответ
8
Существует. Вы можете добавить свой вид к основному window
и перенести его на передний план, когда вам нужно.
В следующем коде предполагается, что _viewConroller
и _anotherView
являются прочными свойствами appDelegate - конфигурация может быть разной.
Этот код добавит маленький синий квадрат в верхнем левом углу экрана.
- (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 как раскадровки ID
Дополнительные методы
-(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];
}
Смежные вопросы
- 1. View over view breaks hierarchical
- 2. Javadoc «mouse over» view
- 3. fortran test over over over
- 4. Iterate over JSON in View
- 5. ClickView ImageView over List view
- 6. Android - View Over Media Player
- 7. Коммутационные контроллеры View over Swift
- 8. view with navigationController over tabBarController
- 9. SQL DataReader Over Complex View
- 10. Cardlib Card over over
- 11. Ошибка BigQuery: «OVER» «OVER» «
- 12. загрузить UIViewController view over singleViewController style app
- 13. canvas arc y-over over
- 14. plink Password Over and Over
- 15. В чем преимущество использования Space over View
- 16. Slide Over and Split View не разрешает
- 17. UIImage View over navBar и statusBar
- 18. split view/pop-over maintenance selection
- 19. View over ListView приводит к исключению ClassCast
- 20. mysql view over single table performance
- 21. Laravel Iterating Over Collection In View
- 22. jQuery wait for ajax call over over
- 23. C# .net looping thread over over
- 24. PHP Изменить массив Over и Over
- 25. Onclick over viewPager - Android
- 26. Android EditText over SurfaceView
- 27. fragmenttransaction over listview
- 28. UIImageView Slide Over
- 29. UIButton in Modal View over UIToolBar Over UITabBar Touch не обнаружен
- 30. Iterate over SQLOBJECT -WEBSQL
Хорошо, будет ли это работать, когда вы используете раскадровку? – thvanarkel
Я верю, что это нужно, но я не пробовал. Возможно, вам придётся сделать метод для переноса _anotherViewToFront и вызвать его после того, как viewControllers изменят места. –