subview

UserInteraction enable for subview only

微笑、不失礼 提交于 2019-11-30 03:26:19
问题 I have a view and view.UserInteractionenabled = no and a button is added to the view. i need to click the button only . is it possible to enable interaction for button only. 回答1: A view cannot receive touches unless userInteractionEnabled is YES for the view and all of its superviews up to the UIWindow object. You can make a subclass of UIView to contain the button, and make it ignore touches outside the button by overriding hitTest:withEvent: . Example: @interface MyView : UIView @property

IOS, UIView, Detect Hidden State Change in Subview

风流意气都作罢 提交于 2019-11-30 02:08:06
问题 Is there anyway to detect a hidden state change (or other change) in a sub view in a UIView (not UIViewController). Would like to detect this async somehow. There are reasons for my madness. 回答1: You can use KVO (key value observing) to detect a change to the value of the property hidden . Add your observer ( self in this example) in the following way: UIView* viewToObserve = [self getViewToObserve]; // implement getViewToObserve [viewToObserve addObserver:self forKeyPath:@"hidden" options:0

Autolayout and subviews

混江龙づ霸主 提交于 2019-11-29 22:58:51
I am using the iAd suite with storyboards from Apple, as per this link... Apple iAd Storyboard documentation It all works fine until I turn autolayout on. It builds fine but crashes on running. The output I get is: 2013-08-24 12:06:36.138 TabbedBanner[7272:c07] * Assertion failure in -[UIView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2380.17/UIView.m:5781 2013-08-24 12:06:36.139 TabbedBanner[7272:c07] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after sending -viewDidLayoutSubviews to the view controller.

Swift: Get all subviews of a specific type and add to an array

。_饼干妹妹 提交于 2019-11-29 22:54:03
I have a custom class of buttons in a UIView that I'd like to add to an array so that they're easily accessible. Is there a way to get all subviews of a specific class and add it to an array in Swift? vadian The filter function using the is operator can filter items of a specific class. let myViews = view.subviews.filter{$0 is MyButtonClass} MyButtonClass is the custom class to be filtered for. Here you go extension UIView { /** This is the function to get subViews of a view of a particular type */ func subViews<T : UIView>(type : T.Type) -> [T]{ var all = [T]() for view in self.subviews { if

How can I insert a subview below the other subviews

霸气de小男生 提交于 2019-11-29 22:52:29
everyone. I have some labels that I draw them in the xib file, and add a background view using codes,but the background view is in the front of these labels, so I cant see them. So, my question is how can I add a background view below these labels. Thank you in advance. If you Google UIView you'll end up at the documentation - UIView Class Reference Then you need to look down the list of methods until you find something that sounds like it will roughly fit your needs like these two: - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index and - (void)insertSubview:(UIView *)view

How to create an alert in a subview class in Swift?

被刻印的时光 ゝ 提交于 2019-11-29 12:29:42
I have a view controller which contains a sub-view. And inside the sub-view class, I may need to pop out an alert when some condition is satisfied. class GameViewController: UIViewController { @IBOutlet var gameBoardUIView: GameBoardUIView ... } class GameBoardUIView: UIView { ... func move() { if !gameBoard.checkNextMoveExist() { var alert = UIAlertController(title: "Game Over", message: nil, preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Take Me Back", style: UIAlertActionStyle.Cancel, handler: {(action: UIAlertAction!) in println("Taking user back to the

iPhone subview flip between 2 views

假如想象 提交于 2019-11-29 08:44:49
问题 iPhone / Objective-C On my view a little "hover" view appears after a user clicks on a button on the main view. When the user clicks this subview I want the subview to FlipFromRight to another view (same size). The main view underneath should stay. viewHot and viewCold are the subviews viewMain is the main one. Is this possible? 回答1: Create another empty view in viewMain called viewHover and position it where you want the hover views to show. Then in IB add either viewHot or viewCold (not

Make subview rotate too when device is rotated iPhone/iPad

那年仲夏 提交于 2019-11-29 07:28:32
Let me explain what I mean when I say that I want to rotate my subview too. I placed a lot of images to make my self clear. This may look like to much but it is not. Just wanted to be clear. In the nib file that I am currently working on, I have a UIView and button. The UIView that I created in interface builder is connected with the IBOutlet named ViewMain: and the button executes the following method: and what that method does is that it places the view from another nib file in the UIView controller that I created in interface builder. The nib file that I am actually placing is: I just

Draw Line with gesture

早过忘川 提交于 2019-11-28 22:08:21
I add a view as sub view using the following code imageview = [[UIImageView alloc] initWithFrame:[holderView frame]]; [imageview setImage:cppobject->OutputImage]; imageview.contentMode = UIViewContentModeScaleAspectFit; [holderView addSubview:imageview]; holderView.contentMode = UIViewContentModeScaleAspectFit ; UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)]; [pinchRecognizer setDelegate:self]; [holderView addGestureRecognizer:pinchRecognizer]; [pinchRecognizer release]; UIRotationGestureRecognizer *rotationRecognizer

UITextView change height instead of scroll

风格不统一 提交于 2019-11-28 22:03:00
By default, the UITextView's contentView becomes scrollable when there is too much text to fit into the textview based on it's height. I'd like to disable this and instead, update the height of the UITextView to fit in the text. The reason I'm doing this is because I'm adding the UITextView as a subview of a UIScrollView which should handle the scrolling, much like in the native Mail app (when you enter text, the whole view scrolls up, not just the textview. Anyone got some ideas / has run into the same problem before? It is very simply done like this: CGRect frame = textView.frame; frame.size