I have a custom uiview that i am trying to update the frame size. I do it like this in a method once it is clicked. The method is called, and the frame value changes, however on the screen nothing happens! What I think is happening is the subclass is not being redrawn or updated
- (void)resizeWithTag:(int)tag wasTouched:(BOOL)touched
{
if (!touched) {
GameBox *box = (GameBox *)[self.view viewWithTag:40];
CGRect frame = box.frame;
frame.origin.x += 30;
box.frame = frame;
[[self.view viewWithTag:40] setFrame:CGRectMake(20, 20, 100, 73)];
[box layoutSubviews];
NSLog(#"%f", box.frame.origin.x);
markButton.enabled = NO;
guessButton.enabled = NO;
[self.view reloadInputViews];
NSLog(#"The action bar should now be hidden");
}
else if (touched) {
guessButton.enabled = YES;
markButton.enabled = YES;
[self.view reloadInputViews];
NSLog(#"The action bar should now be visible");
}
}
Related
I am adding many UIImageView's to UIScrollView,with paging enabled.I need to zoom only the image that i have tapped to zoom,rather than zooming the entire scrollview.Also zooming a particular image doesnot scale other subviews.
- (void)loadScrollViewWithImages {
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width * imageList.count, self.view.bounds.size.height);
scrollView.pagingEnabled = YES;
UIView *mainView = [[UIView alloc] initWithFrame:self.view.bounds];
CGFloat xPos = 0.0;
for (UIView *subView in scrollView.subviews) {
[subView removeFromSuperview];
}
int i = 0;
for (NSDictionary *imageDetails in self.imageList) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xPos, 0.0, self.view.bounds.size.width, self.view.frame.size.height)];
imageView.contentMode = UIViewContentModeScaleAspectFill;
[imageView setClipsToBounds:YES];
[mainView addSubview:imageView];
xPos += self.view.bounds.size.width;
[imageView setImageWithURL:[NSURL URLWithString:[imageDetails objectForKey:#"media_path"]]];
[self.imageViewArray addObject:imageView];
if(self.selectedImageIndex == i) {
self.selectedImageView = imageView;
}
i++;
}
[mainView setFrame:CGRectMake(mainView.frame.origin.x, mainView.frame.origin.x,self.view.bounds.size.width * imageList.count, self.view.bounds.size.height)];
[scrollView addSubview:mainView];
}
I wanted to zoom only the selected index,but other subviews also add to the screen with no scaling.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [[[scrollView.subviews objectAtIndex:0] subviews] objectAtIndex:0] ;;
}
for implementing this you have to take a main scrollview as you have taken and instead of displaying imageView in this scrollview you have to take another scrollview and display the image and when user tries to zoom the image then only the selected scrollview gets scrolled.
I am creating a app that display subview like ActionSheetView and in that i have added UIGridView and UIPageControll thru outlet , but now when i click the cell it does not respond ,my subview is a ViewController with the nib file.
and if i create a button and add in my popupview programmatically then it wil displaying, and also get the click event, but anything in outlet does not respond.
i have tried to set userinteraction enable in my subview but it does not done any good.
here is my code for first view that display subview by clicking barbutton:
- (void)popUpView:(id)sender {
//self.view.backgroundColor = [UIColor darkGrayColor];
bGView = [[UIView alloc] init]; /this is the background view and all view is added in it
bGView.frame = CGRectMake(0,0,320,490);
bGView.backgroundColor = [UIColor clearColor];
bGView.alpha = 0.8 ;
CGRect viewFrame = CGRectMake(10, 90, 300, 300);
aPopUpViewController = [[PopUpViewController alloc] initWithNibName:#"PopUpViewController" bundle:nil]; //this is my view controller and when this shows on screen it display my greed view
aPopUpViewController.view.frame = viewFrame;
aPopUpViewController.view.userInteractionEnabled = YES;
[bGView addSubview:aPopUpViewController.view];
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
button.backgroundColor = [UIColor clearColor];
[button setBackgroundImage:[UIImage imageNamed:#"close_button.png"] forState:UIControlStateNormal];
button.frame = CGRectMake(-1, 80, 30, 30);
[bGView addSubview:button];
//for view animation
/*
// from bottom to center animation
[bGView setFrame:CGRectMake( 0.0f, 480.0f, 320.0f, 480.0f)]; //notice this is OFF screen!
[UIView beginAnimations:#"animateTableView" context:nil];
[UIView setAnimationDuration:0.4];
[bGView setFrame:CGRectMake( 0.0f, 0.0f, 320.0f, 480.0f)]; //notice this is ON screen!
[UIView commitAnimations];*/
//for page like effect
/*[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCurlUp //change to whatever animation you like
animations:^ { [self.view addSubview:bGView]; }
completion:nil];*/
/*CATransition *transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionReveal; //choose your animation
[bGView.layer addAnimation:transition forKey:nil];
[self.view addSubview:bGView];*/
aPopUpViewController.view.userInteractionEnabled = YES;
bGView.userInteractionEnabled = YES;
self.view.userInteractionEnabled = YES;
bGView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
bGView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
// do something once the animation finishes, put it here
}];
[self.view addSubview:bGView];
addLabel.enabled = NO;
clipArt.enabled = NO;
emailItem.enabled = NO;
closeButton.enabled = NO;
self.navigationController.topViewController.title = #"Choose ClipArt";
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.navBarHide = #"no";
}
- (void)aMethod:(id)sender
{
//[aPopUpViewController.view removeFromSuperview];
//[button removeFromSuperview];
/*[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve//change to whatever animation you like
animations:^ { [bGView removeFromSuperview]; }
completion:nil];*/
[bGView removeFromSuperview];
addLabel.enabled = YES;
clipArt.enabled = YES;
emailItem.enabled = YES;
closeButton.enabled = YES;
self.navigationController.topViewController.title = #"Greeting's";
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.navBarHide = #"yes";
}
and this is how my screen look like
UPDATE
now i figured out my problem,problem is that i have given my whole view a tap listner,now i am adding grid view as subview so when ever i tap on cell rather then do select cell it will generate view tap gesture and thats why cell never selected,that's what i think..
add this line after you add every subviews in your main view..
[self.view bringSubviewToFront:yourGridView];
I am looking for an example that show just vertical scrolling in iPhone.
The Apple supplied Scrolling example allows swiping of images left to
right.
Example Link
Example Link
I want to have my images scroll top to bottom like Instagram
App.
I research about it and found lots of example, but they all show
horizontal scrolling.
Example
Example
Example
Does anyone know how to do this?
I appreciate if you send me a link to a tutorial.
Hi i solved your problem with apple code,
just change the function with
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(0,curXLoc);
view.frame = frame;
curXLoc += (kScrollObjHeight);
}
}
// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake(([scrollView1 bounds].size.width),kNumImages * kScrollObjHeight)];
}
or if you want sample then i will give you
For your purpose refer your link:
http://idevzilla.com/2010/09/16/uiscrollview-a-really-simple-tutorial/
There is a code like:
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
For horizontal scrolling you need to set the width of contentSize property to a higher value than the scroll view's frame width. Likewise for vertical scrolling you need to set the height of contentSize property to a higher value than the scroll view's frame height.
Reference
In the above code it can be done like:
scroll.contentSize = CGSizeMake(self.view.frame.size.width, numberOfViews * self.view.frame.size.height);
You can use the following code to scroll images from top to bottom and vice versa.!!
- (void)viewDidLoad
{
//....
UISwipeGestureRecognizer *recognizer;
//for scrolling up
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(SwipeUp)]; // calling method SwipeUp
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[[self view] addGestureRecognizer:recognizer];
//for scrolling down
UISwipeGestureRecognizer *recognizer1;
recognizer1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(SwipeDown)]; //calling method SwipeDown
[recognizer1 setDirection:(UISwipeGestureRecognizerDirectionDown)];
[[self view] addGestureRecognizer:recognizer1];
}
//Initialise and synthesise IBOutlet UIImageView *bgImage;
-(IBAction)SwipeUp
{
[bgImage setImage:[UIImage imageNamed:#"yourImage1"] ];
bgImage.opaque=YES;
[self.view addSubview:bgImage];
}
-(IBAction)SwipeDown
{
[bgImage setImage:[UIImage imageNamed:#"yourImage2"] ];
bgImage.opaque=YES;
[self.view addSubview:bgImage];
}
I don't know if I understood correctly what you want to accomplish but basically you can set the position of you scrollView using setContentOffset.
CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - self.scrollView.bounds.size.height);
[scrollView setContentOffset:bottomOffset animated:YES];
There are several ways of doing this for example:
Using the UITableView with Custom cell
Adding UIScrollingView & adding the content/images & increasing the
height of scrollview according to number of objects in array.
Here is the code snippet which creates a 2*2 Grid for images :
//Over here adding the image names into the Array
NSMutableArray *imageArray=[[NSMutableArray alloc]init];
[Arr addObject:[UIImage imageNamed:#"image_1.png"]];
[Arr addObject:[UIImage imageNamed:#"image_2.png"]];
[Arr addObject:[UIImage imageNamed:#"image_3.png"]];
[Arr addObject:[UIImage imageNamed:#"image_4.png"]];
[Arr addObject:[UIImage imageNamed:#"image_5.png"]];
// Initlaizing the ScrollView & setting the frame :
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,320, 460)];
[scrollView setBackgroundColor:[UIColor clearColor]];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
int row = 0;
int column = 0;
for(int i = 0; i < imageArray.count; i++) {
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor=[UIColor clearColor];
button.frame = CGRectMake(column*160+0,row*210+10, 160, 190);
[button setImage:[imageArray objectAtIndex:i] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor clearColor]];
[button addTarget:self action:#selector(chooseCustomImageTapped:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[view1 addSubview:button];
if (column == 1) {
column = 0;
row++;
} else {
column++;
}
}
[scrollView setContentSize:CGSizeMake(320, (row+1) * 210)];
[self.view addSubview:view1];
//Here is the method used for Tapping :
- (IBAction)chooseCustomImageTapped:(id)sender
{
}
Now,once the scrollView is ready for Vertical scrolling, you can do your own customization accordingly. I hope this would work for you.
i have a UITableViewCell, and i am trying to add an animation that causes a layer to scroll off of the cell, the problem is it gets clipped by the cell above it, is there an easy way to get around this?
here is my method.
- (void)animateLife:(UIButton *)sender isPositive:(BOOL)state{
// Reset lCount if we are pressing a different button than last time.
if (sent != sender) {
lCount = 0;
}
sent = sender;
// Increase the count by 1.
lCount = lCount + 1;
// Set up some properties.
CGPoint origin = sender.center;
CGPoint newOrigin = CGPointMake(origin.x, (origin.y - 100));
NSString *oper = [[NSString alloc] init];
// Check to see if this is a + or - change.
if (state == true) {
oper = #"+";
} else {
oper = #"-";
}
// Alloc a String and a Label to hold it.
NSString *characters = [[NSString alloc] initWithFormat:#"%#%d", oper, lCount];
UILabel *theLabel = [[UILabel alloc] initWithFrame:CGRectMake(origin.x,origin.y , 50, 50)];
// Configure the Label.
if (oper == #"-") {
[theLabel setTextColor:[UIColor redColor]];
} else {
[theLabel setTextColor:[UIColor greenColor]];
}
[theLabel setText:characters];
[theLabel setBackgroundColor:[UIColor clearColor]];
[theLabel setAlpha:1];
[theLabel setCenter:origin];
[theLabel setShadowColor:[UIColor blackColor]];
[theLabel setShadowOffset:CGSizeMake(0.5, 0.5)];
[theLabel setFont:[UIFont fontWithName:#"Helvetica" size:28]];
[theLabel setTextAlignment:UITextAlignmentCenter];
[theLabel.layer setShadowRadius:3];
[theLabel.layer setShadowOpacity:0.9];
// Display our Label.
[sender.superview insertSubview:theLabel aboveSubview:sender];
// Setup animation.
[UIView beginAnimations:#"lifeCount" context:nil];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:)];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[theLabel setCenter:newOrigin];
[theLabel setAlpha:0];
// Commit Animation.
[UIView commitAnimations];
fCount = fCount + 1;
// Clean up.
[theLabel release];
[characters release];
[oper release];
}
- (void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
// Since an animation finished, reduce count by one.
fCount = fCount - 1;
//check if all animations are finished, if so, reset the lCount.
if (fCount < 1) {
lCount = 0;
}
}
Update: it appears if i scroll cells to where they get reused, then the animation shows up properly is there a way i can make it not require the reuse?
In your method cellForRowAtIndexPath there is probably code like this:
cell = [tableView dequeueReusableCellWithIdentifier:someCellID];
if ( cell == nil ) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:kCellID] autorelease];
}
Do not call the "dequeueReusableCellWithIdentifier" method. Just create new cell each time.
Note that if you have a lot of rows in your table, this will have a performance hit.
problem in adding second UIbutton in cameraOverlayView ,here i am able to add the first button but not able to add second button with following code
- (void)pickAndDecodeFromSource:(UIImagePickerControllerSourceType) sourceType {
[self reset];
// Create the Image Picker
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
UIImagePickerController* aPicker =
[[[UIImagePickerController alloc] init] autorelease];
aPicker.sourceType = sourceType;
aPicker.delegate = self;
self.picker = aPicker;
// [[NSUserDefaults standardUserDefaults] boolForKey:#"allowEditing"];
BOOL isCamera = (sourceType == UIImagePickerControllerSourceTypeCamera);
if ([picker respondsToSelector:#selector(setAllowsEditing:)]) {
// not in 3.0
[picker setAllowsEditing:!isCamera];
}
if (isCamera) {
if ([picker respondsToSelector:#selector(setShowsCameraControls:)]) {
[picker setShowsCameraControls:NO];
UIButton *cancelButton =
[UIButton buttonWithType:UIButtonTypeRoundedRect];
NSString *cancelString =
NSLocalizedString(#"DecoderViewController cancel button title", #"");
CGFloat height = [UIFont systemFontSize];
CGSize size =
[cancelString sizeWithFont:[UIFont systemFontOfSize:height]];
[cancelButton setTitle:cancelString forState:UIControlStateNormal];
//cancelButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"CancelButtonForButton.png"]];
//cancelButton.backgroundColor = [UIColor clearColor];
//cancelButton.backgroundColor = [UIColor greenColor];
[cancelButton setImage:[UIImage imageNamed:#"cancelForButton.png"] forState:UIControlStateNormal];
//[cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
CGRect appFrame = [[UIScreen mainScreen] bounds];
static const int kMargin = 10;
static const int kInternalXMargin = 10;
static const int kInternalYMargin = 10;
CGRect frame = CGRectMake(kMargin,
appFrame.size.height - (height + 2*kInternalYMargin + kMargin),
2*kInternalXMargin + size.width,
height + 2*kInternalYMargin);
[cancelButton setFrame:frame];
[cancelButton addTarget:self
action:#selector(cancel:)
forControlEvents:UIControlEventTouchUpInside];
picker.cameraOverlayView = cancelButton;
// The camera takes quite a while to start up. Hence the 2 second delay.
[self performSelector:#selector(takeScreenshot)
withObject:nil
afterDelay:2.0];
//cancelButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg.png"]];
}
}
// Picker is displayed asynchronously.
[self presentModalViewController:picker animated:YES];
} else {
NSLog(#"Attempted to pick an image with illegal source type '%d'", sourceType);
}
}
The issue is that you are replacing the camera overlay with the first button - so creating the second button and using "picker.cameraOverlayView = newButton;" replaces the camera-overlay again.
The solution is to create a parent UIView, add both buttons to it, and then set the camera overlay to be the parent UIView.