Có thể trên iOS rằng chế độ xem luôn luôn nổi trên tất cả các chế độ xem khác. Tôi hỏi điều này vì những gì tôi muốn đạt được là một khung nhìn nổi trên ViewController, và sau đó là một Modal View Controller sẽ xuất hiện, trong khi khung nhìn cụ thể vẫn còn trôi nổi trên Modal View Controller đó (hy vọng bạn sẽ có được những gì tôi đang cố gắng nói).Xem nổi trên tất cả các ViewControllers
5
A
Trả lời
8
Có. Bạn có thể thêm chế độ xem của mình vào chính window
và đưa nó lên phía trước khi bạn phải.
Trong mã sau được coi là _viewConroller
và _anotherView
là các thuộc tính mạnh mẽ của appDelegate - tất nhiên cấu hình có thể khác nhau.
Mã này sẽ thêm hình vuông nhỏ màu xanh lam ở góc trên bên trái của màn hình.
- (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
Bạn có thể làm như sau nếu bạn đang sử dụng kịch bản và autolayout (lấy cảm hứng từ trả lời đầu tiên)
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
tất cả các bạn cần làm là để kéo một bộ điều khiển nhìn vào bạn storyboard chính với FloatingController như một ID storyboard
Phương pháp bổ sung
-(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];
}
Các vấn đề liên quan
- 1. Trường hợp đơn lẻ AdMod trong tất cả ViewControllers
- 2. Làm cách nào để xem tất cả các dự án tôi đang xem trên github?
- 3. Các nút nổi Android trên một chế độ xem
- 4. Có quyền xem ViewControllers với nhiều mã không?
- 5. Chế độ xem nổi trên Android (trên các chế độ xem khác)
- 6. Có thể xem các sự kiện trên tất cả các nút con cháu trong ZooKeeper không?
- 7. Xem tất cả các lớp học siêu trong Java
- 8. Xem tất cả các tệp đã thay đổi trong TFS
- 9. Ẩn tất cả các bộ điều khiển xem phương thức
- 10. Đặt GestureDetector cho tất cả các chế độ xem con
- 11. Xem tất cả biến đã xác định
- 12. Xóa tất cả các bản xem trước khỏi UIScrollView?
- 13. Cách xem nhật ký của tất cả các lệnh?
- 14. Kiểm tra xem tất cả các thẻ có bị đóng
- 15. Tìm tất cả các tài liệu tham khảo để xem
- 16. Backbone.js - Xóa tất cả các chế độ xem phụ
- 17. Tất cả các GUID thư mục ảo nổi tiếng là gì?
- 18. Làm cách nào để tìm nạp tất cả các bài đăng trên WordPress bằng hình ảnh nổi bật?
- 19. Thêm UIView trên tất cả các chế độ xem khác, bao gồm StatusBar
- 20. Cách xem/tải tất cả các bài đăng trên tường của một trang Facebook cụ thể
- 21. Đặt UIView lên trên tất cả các chế độ xem khác
- 22. Vẽ để xem trực tiếp trên đầu trang của tất cả các cửa sổ
- 23. Xem tất cả `git diffs` với vimdiff
- 24. Chọn tất cả các phần tử trên một trang
- 25. Hiển thị tất cả các tên kiểm tra trên Bamboo
- 26. Vẽ canvas Android lên trên tất cả các ứng dụng?
- 27. jQuery từ bỏ tất cả các yêu cầu AJAX nổi bật
- 28. Làm nổi bật TODO ở tất cả các chế độ lập trình
- 29. Nếu tất cả các bit là 0, giá trị của điểm nổi IEEE là gì?
- 30. bootstrap affix nổi tất cả các con đường bên trái khi cuộn
Ok, điều này cũng sẽ hoạt động khi bạn đang sử dụng bảng phân cảnh? – thvanarkel
Tôi tin rằng nó nên, nhưng tôi đã không thử nó ra. Có thể bạn sẽ phải tạo một phương thức để mang _anotherViewToFront và gọi nó sau khi viewControllers thay đổi địa điểm. –