Flip UIView (reversi style) - objective-c

I'm trying to make a reversi game, and want to flip a piece to the opposite color. So when a white piece is flipped, it becomes black, and the other way around.
I know you can flip a UIView with the code below, but can't figure out how to flip it to another image.
In my "Piece" class, I have a UIButton with the black or white image. Do I need to create two buttons, and then flip them somehow?
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:card cache:YES];
Thanks in advance

I would do this to do a transition from the white button to the black button in 0.4s.
You need to have your white and black buttons already as subviews of some other view. For this transition the black button should be hidden before doing the transition.
UIViewAnimationOptionShowHideTransitionViews says that your fromView will be hidden after the transition.
The flip will occur in the whiteButton superview.
[UIView transitionFromView:whiteButton
toView:blackButton
duration:0.4f
options:UIViewAnimationOptionTransitionFlipFromRight |
UIViewAnimationOptionShowHideTransitionViews
completion:^(BOOL finished){}];

Related

UITextView not Responding to Touch Events after Animation

I am performing an animation to correctly keep the UITextView at the bottom of the screen if I expand the view. For some reason if I perform the animation, the UITextView stop responding to touch events, so there is no keyboard that will show up.
All I am doing is:
CGRect newSendTextView = self.commTextView.frame;
newSendTextView.origin.y = (newSendTextView.origin.y + (height - self.defaultSize.size.height));
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.5];
self.commTextView.frame = newSendTextView;
[UIView commitAnimations];
I know the UITextView is still on the screen after I do the transformation since I colored the UITextView background a bright blue, but it doesn't want to respond to any touch events.
If I comment out self.commTextView.frame = newSendTextView; so that it doesn't move, the touch events register.
I have no idea why this happens, I tried
[self.commTextView becomeFirstRespond];
and I have checked if isEditable and isUserInteractionEnabled is set to 1 and it is.
I guess, new position of TextView might be getting overlayed by other view. Check any other View is having same frame on your TextView new position. Use clipsToBounds property to find it.

UIView clipToBounds is not stopping a subView receiving touches outside the parent view

I have two UIViews. I'm using one to contain the other so that I can slide one inside the other. I'm encountering an issue where even though a subView is clipped to the bounds of its parent, it is still receiving touch events and blocking access to other underlying views.
I have three screenshots that show the layout. I've coloured the parent green and the child red.
The idea is that the user clicks "View" and the subView slides up. When the subView is in the default position, the UITabBar is covered and cannot be clicked. You can see this in the first image where the red view is present at the bottom. When the subView is moved to the top, the UITabBar can be clicked as it's now visible. In the third image, I've show what it's like with clipToBounds enabled on the green UIView.
I've enabled clipToBounds, so I cannot understand why the subView is blocking the underlying UITabBar. Is my understanding of clipToBounds completely wrong??
Using clipToBounds only affects the visual layout of a subView, not the logical layout. This means that whilst my subView isn't visible to the eye, it's visible to touch.
I've worked around this issue by animating the size of the subView rather than its position. In my code below, the stationProximityView is the subView. I animate its size by 40 pixels to bring the black title back into view.
[UIView beginAnimations:#"stationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectOffset(self.stationProximityView.view.frame, 0, -40);
[UIView commitAnimations];
When I no longer need it, I animate it out of view.
[UIView beginAnimations:#"stationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectMake(0 ,0, 320, 500);
[UIView commitAnimations];
If the user taps the view button, the entire subView is shown:
[UIView beginAnimations:#"stationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectMake(0,460,320,40);
[UIView commitAnimations];
Dismissal causes the view to be hidden in the same way as the small bar.
[UIView beginAnimations:#"hideStationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectMake(0,0,320,500);
[UIView commitAnimations];
At the moment, this code is only being tested on the iPhone 5, so the hard-coded height of 500 would causes issues on previous iPhone models.

UIColor groupTableViewBackgroundColor is transparent

I have a grouped style UITableView on my navigation stack, and when I click on a cell, I push a UIDatePicker onto the stack. The problem is that I want this custom view to have the same background color as my table view.
I tried setting the background color of my custom view like:
datePicker.backgroundColor = [UIColor groupTableViewBackgroundColor];
But this comes out transparent. I also tried modifying the underlying CGColor object to have an alpha of 1.0, which caused the background color to be black.
The following does work as expected:
datePicker.backgroundColor = [UIColor lightGrayColor];
But, of course, this color doesn't quite match the grouped table background color.
Am I going about this all wrong? I found a similar post about this here, but no helpful response.
What do you mean you "push a UIDatePicker onto the stack"? Why dont you try animating the UIDatePicker into view?
when the view loads, create the picker and set the frame off screen, such as
[picker setFrame:CGRectMake(0,960,320,216)];
then instead of "pushing" the picker, animate it into view like:
[UIView beginAnimations:nil context:NULL];
[picker setFrame:CGRectMake(0,200,320,216)];
[UIView commitAnimations];
And when you want to dismiss the picker, just hide it like:
[UIView beginAnimations:nil context:NULL];
[picker setFrame:CGRectMake(0,960,320,216)];
[UIView commitAnimations];
If you need to, you can also add a toolbar with a "done" button to dismiss the picker, works great for me.
If the contents of the picker are going to be displayed on the table, then you can set the frame of the table in that animation sequence. in the first one, make the table half the size (like 150 for my example would work perfect), then in the hide sequence, make the table the original size (415 for this example). And when you hide the picker, call [tableView reloadData]; to refresh the table.

Animate UITextViews

I have a View with one UITextView in the top half, one UIImageView on the bottom half and a button in the middle, between them. What I'm trying to do is every time I press the button, the UITextView must change the text (it gets it from a sqlite db). I managed to do that, but now I want to animate the text change. So I want the UITextField to fade out to the left, then fade in from the right with a the new text inside.
Now i followed the ViewTransition documentation and created a second UITextView so I can animate between them. The only problem is that animation happens to the entire view. So even the image and the button slides in every time. I just want to animate the text view(s).
How would i go about doing that?
[UITextView beginAnimations:nil context:NULL];
[UITextView setAnimationDuration:0.5];
self.firstTextView.transform = CGAffineTransformMakeTranslation(-100, 0);
self.secondTextView.transform = CGAffineTransformMakeTranslation(-100, 0);
[UITextView commitAnimations];

Animate the change of a stroke color on UIView

I'd like to "pulse" the stroke color on a path that I've drawn in a UIView's drawRect. But not sure this is possible?
- (void)highlightView {
if (!isHighlighted) {
[UIView beginAnimations:NULL context:nil];
[UIView setAnimationDuration:0.75];
self.strokeColor = kHighlightColor;
self.strokeWidth = 2.0;
[UIView commitAnimations];
self.isHighlighted = YES;
}
}
I'm only able to see the change if i setNeedsDisplay on the view. But that bypasses the animation. I can think of a few workarounds if this isn't possible like overlaying another semi-transparent view with the proper color and just fading it in... but for some reason I thought animating color properties was possible in Cocoa?!? Perhaps I'm mistaken. Hopefully one of you can set me straight.
You absolutely can animate colour properties with UIView, but it doesn't really make sense in the context you're dealing with right now.
In drawRect: you are essentially painting a colour when you stroke a path, those bits just get blitted to the screen. At that point, the colour isn't really a property of the view so much as part of the painting.
I wrote a UIView that pulsed this summer (emulating the "In Call" status bar) by creating two UIViews stack atop each other, and animating both of their color properties.