iOSでは、ビューが他のすべてのビューよりも常に浮動している可能性がありますか。私はこれを尋ねます。なぜなら、私が達成したいのはViewControllerの上に浮かぶビューで、Modal View Controllerはスライドしていますが、その特定のビューはまだモーダルView Controller上に浮いています。 )。ViewControllerの上にフローティングを表示
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
あなたはすべてを行う必要がとあなたのメインストーリーボードにビューコントローラをドラッグすることである
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
(最初の回答に触発さ)ストーリーボードと自動レイアウトを使用している場合は、次の操作を行うことができますストーリーボードIDとして 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];
}
関連する問題
- 1. 別のviewController、SwiftでviewControllerを表示
- 2. navigationControllerにviewControllerを表示
- 3. 半画面上にViewControllerを表示する方法
- 4. ViewControllerを別のものに表示
- 5. 別のViewControllerビュー内にViewController全体を表示
- 6. (テーブル)ViewControllerから(テーブル)ViewControllerをTabBarController内のNavigationController内に表示
- 7. IOSのリンク項目をviewcontrollerに表示
- 8. フレックスボックスフォールバック。フローティング列には表+表セルが表示されます
- 9. AppDelegateからViewControllerを表示
- 10. navigationcontrollerの下から上へviewcontrollerを表示/非表示するにはどうすればいいですか?
- 11. TabBarControllerから特定のViewControllerを表示
- 12. iphone viewControllerのPDFファイルを表示
- 13. フローティング部門にファイルアップローダを表示する方法は?
- 14. ストーリーボードでのNibビューの表示ViewController
- 15. フローティング・ピック・リストを表示するためのJquery Plugin/Widget?
- 16. Twitterkitは、代わりに新しいviewcontrollerをターゲットviewControllerに表示します。
- 17. UIImagePickerControllerでViewControllerを表示する方法
- 18. Swift jpg画像をviewControllerから表示
- 19. PopContopとしてViewControllerを表示
- 20. ナビゲーション項目のタイトルviewcontrollerビューで表示
- 21. iOSのviewcontrollerにデフォルトのカレンダーを表示するには
- 22. SVG要素上のテキストを表示上に表示
- 23. ViewControllerのモーダルプレゼンテーションと一緒にiOSキーボードを表示するには?
- 24. タブバーのViewControllerに戻るボタンを表示するには?
- 25. ストーリーボードの1つのViewControllerのNavigationBarを非表示にする
- 26. ストーリーボード内の1つのViewControllerにステータスバーを表示しない
- 27. ログイン成功後に別のViewControllerを表示する方法
- 28. 複数のViewControllerを同時に表示するIOS
- 29. 既存のtableviewcontrollerに.xib viewcontrollerを表示できません
- 30. フローティング画像の上にドロップダウンメニューを重ねる
ストーリーボードを使用しているときにも、これは機能しますか? – thvanarkel
私はそれを信じなければならないが、私はそれを試していない。 viewControllersが場所を変更した後に_anotherViewToFrontを呼び出して呼び出すメソッドを作成する必要があります。 –