detecting when a UISlider finishes Xcode - uiimageview

I have a UISlider that makes a UIImageView move from side to side by setting the x value in CGRectMake the UISlider.value. I want to detect when the slider stops so I can have another action happen. How would I go about detecting when the UISlider stops and then write an if statement to do something else.

I found out that all I needed to do was add
[zoomSlider addTarget:self action:#selector(stopSlider)
forControlEvents:UIControlEventTouchUpInside];
inside the IBACTION for my slider and then add
-(void) stopSlider;{
with whatever code I wanted to happen when I stop touching the slider here
}

Related

UISwitch doesn't work on Google Maps SDK for iOS?

I'm trying to create a UISwitch laid on mapView_ of Google Maps for my iOS app, but it seems not to work.
In details, I first followed instruction from google, created mapView_, then made it my viewcontroller's view:
self.view = mapView_;
Then, I created an UISwitch programmatically and added it as a subview:
mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(50, 360, 0, 0)];
[mySwitch setBackgroundColor:[UIColor clearColor]];
[mySwitch addTarget:self
action:#selector(changeSwitch:)
forControlEvents:UIControlEventTouchDown];
[mapView_ addSubview:mySwitch];
But when I touched the switch both in simulator and device, it didn't change its state from ON->OFF or OFF->ON. I even tried different UIControlEvent, such as UIControlEventValueChanged but it didn't work. To make sure that the code should work, I tried on a normal view of a normal test viewcontroller (that means, not using google maps), it worked fine!
Does anyone have any comment about this issue?
Thanks heaps!
You can work around this issue by adding both the UISwitch and the GMSMapView to a single UIView parent, instead of adding the UISwitch as a child of a GMSMapView. Yes, this means you need to position both the GMSMapView and the UISwitch.

Subview not appearing where I want it to come out - Xcode

I'm new to XCode and am having trouble getting a subView, when added to the main view, to originate from the bottom whereas the top (which I presume is default).
When I mean top, I don't mean the heir-achy but rather literally top of the screen (where the power button and ear jack of an iphone is).
I have tried to play around with the View -> Origin, and View -> Mode - neither did anything.
I would assume it's the auto-layout but I can't be sure.
Basically, I have a colored mainStoryboard and it [self.view addSubView:[[AnotherView alloc] initWithNibName:#"AnotherView" bundle:nil]];
The AnotherView is just a empty half-sized View.
When it gets added, it keeps appearing from the top. I don't know how to make it come from the bottom.
Do you guys have any insight as to how I might be able to make it come from the bottom?
Thanks ahead of time!
add newView to self.view with the frame
newView.frame=CGRectMake(0,480,320,200);
and after that animate that view by using below animations.
[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationTransitionCurlUp
animations:^{
newView.frame=CGRectMake(0,0,320,200);
} completion:nil];
Or you can use
presentModalViewController: animated:
method

Core Animation action transition: how do it right

I make a test project with one view inside of content view of main window. Window have two buttons: appear & disappear. I want animate view appearance when appear button pressed, and animate dissapearance when dissapear button pressed. And I want do this with layer actions.
In other words, I want to make animation every time view added or removed from superview. So, in code I just want to write [parent addSubview:view] or [view removeFromSuperview] and animation should work in that moments. So, Layer Actions seems fits my needs.
Here is app screenshot and source code (XCode 4.6):
Here is what I did to do that:
I create a view that will appear/dissapear and add layer action:
_coloredView = [[ColoredView alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)];
_coloredView.bgColor = [NSColor yellowColor];
_coloredView.wantsLayer = YES;
// making appear transition from left
CATransition *appearTransition = [CATransition animation];
[appearTransition setDuration:2];
[appearTransition setType:kCATransitionPush];
[appearTransition setSubtype:kCATransitionFromLeft];
[_coloredView.layer addAnimation:appearTransition forKey:kCAOnOrderIn];
Then when appear button clicked, I call
[contentView addSubview:self.coloredView];
When disappear clicked, I call:
[self.coloredView removeFromSuperview];
And seems some part of things works. The yellow rectangle appears as it should first time. But, here is list of very strange things:
I should call addAnimation:forKey: every time when button clicked (after view was disappeared), since after first appearing animation will no longer work.
Disappear won't work at all (If I try add code after view initialization or before disappear button pressed)
When I try to add subview through animator, my transition not work - just default fade-in animation shown.
Seems that during movement from left to right some sort of fading works. It's visible when you set duration to bigger value.
Try #"subviews" instead of kCAOnOrderIn

Cocoa: NSView drawRect painting over IBOutlets

I have an NSView in IB which sits above the app window. I have a subclass of NSView (AddSource) which I assign to the NSView.
On awakeFromNib I instantiate the view:
//add a new Add Source class
addSourceView = [[AddSource alloc] initWithFrame:NSMakeRect(0.0, 959.0, 307.0, 118.0)];
[[winMain contentView] addSubview:addSourceView];
in addSourceView's drawRect method I am adding a white background to the view:
[[NSColor whiteColor] set];
NSRectFill(rect);
[self setNeedsDisplay:YES];//added this to see if it might solve the problem
In winMain's contentView I have a NSButton that when clicked slides the addSourceView onto the window:
NSRect addSourceViewFrame = [addSourceView frame];
addSourceViewFrame.origin.y = 841.0;
[[addSourceView animator] setFrame:addSourceViewFrame];
But it seems as if the app is painting over the IBOutlets I placed on the NSView in IB. If, in IB, I repoistion the NSView so that it is on screen when the app launches everything works fine, the IBOutlets are there as well as the background color.
I'm not sure why this is happening. I've done this before with no problems. I must be doing something different this time.
Thanks for any help.
*note - on the 3rd screen capture, when I say this is what the app looks like when opened, that's when I hard code the Y position of the NSView. When it is functioning correctly it should open as screen capture 1.
Most likely your buttons and custom view are siblings, i.e. they are both subviews of your window's content view. Since siblings are "Stacked" depending on the order in which they are added, when you add the view in code it is being added on top of the buttons. You should be able to fix it by explicitly specifying where the view should be positioned relative to its new siblings like so:
[[winMain contentView] addSubview:addSourceView positioned:NSWindowBelow relativeTo:nil];
which should place it below any existing subviews of your window's content view. Also, remove the setNeedsDisplay: line in drawRect, that leads to unncessary, possibly infinite, redrawing.
EDIT: OK I see what you're doing.
I would suggest creating a standalove view in the NIB by dragging a "Custom View" object into the left hand side (the vertically-aligned archived objects section) and adding your controls there, that should ensure the controls are actualy subviews of the view, then you can just create a reference to the archived view in code, and add/remove it dynamically as needed.
Honestly though, you should probably be using a sheet for these kinds of modal dialogs. Why reinvent the wheel, and make your app uglier in the process?
You added TWO AddSource views to the window. You added one in IB - this view contains your textFields and buttons that are connected to the IBOutlets and it is positioned outside the window.
Then in -awakeFromNib you create another, blank AddSource view (containing nothing) and animate it into the window.
I can't recommend highly enough the Hillegass as the best introduction to IB and the correct way to build Cocoa Apps.
Also, Assertions can be useful to make sure what you think is happening is actually what is happening.
If you are certain you added a button to your view in IB, assert it is so:-
- (void)awakeFromNib {
NSAssert( myButton, #"did i hook up the outlet?");
}
NSAssert is a macro that has zero overhead in a release build.
Calling [self setNeedsDisplay:YES] from -drawRect just causes the same -drawRect to be called again. This will give you big problems.

Initiate a UIPicker from a UIbutton

I would like to make a UIbutton, by press it, it trigger the appearance of a UIPicker from bottom with animation.
May I know how and what code can i initiate the UIpicker from button? And where should i place and set the UIpicker in Interface Builder? and lastly, after choose from the picker, how can it move away?
Many thanks!
You need to look up some documentation on how to make a UIPickerView. There are tons of tutorials out there, even video tutorials. Just search around. It's part of becoming a good programmer.
I personally would set up my picker in interface builder, and set up an IBOutlet to it. I would then, in the .h file of your viewController, set up a method called
-(IBAction)showPicker
Them link the method to your button.
In your .m file of your viewController you should have
-(IBAction)showPicker
{
[UIView beginAnimations];//tells the compiler to start a new animation
[UIView setAnimationDuration:1.0];//in seconds
thepicker.frame = CGRectMake(100, 100, 200, 200);//move the picker to a specific position
[UIView commitAnimations];//tells the compiler to start the animations
}
the beginAnimations and commitAnimations is the code that says any code between us will be animated. So you can animate their alpha (transparency), their positions, and others as well. thepicker refers to your IBOutlet name, whatever you called your picker. I would move the picker out of the screen in your interface builder, then when you press the button, move it into postion with
thepicker.frame = CGRectMake(x,y,width,height);
then, to move it away, just use the same code but change the frame to be out of the screen when you animate it.
BTW, I would create your pickerView first in the viewdidload method, instead of creating it on tapping the button. Otherwise, you will constantly be creating UIPickerViews everytime the button is hit.

Resources