is it possible to create a design something like this?
any help regarding this would be very helpful for me.the functionality i want is to rotate the wheel left-to-right or right to left for selecting time...yellow is selection color and red is shows the remaining time when countdown is running
Use a Gallery view object. Just fill it with the images you want to scroll horizontally.
This would be a good approximation to what you're looking to achieve.
See my video
http://www.youtube.com/watch?v=4acFshAlGJ8
I have use
https://lh3.googleusercontent.com/-WZEDMSmfrK0/TeeD93t8qYI/AAAAAAAAAKw/X9D6jRkLfLk/s800/MUKScale.png
image as Scale in the scrollView this is an incomplete example just to show how can it is achievable.
here is some helpful piece of code,
in this approx everything is static but for the real work one should to work more,
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:scrollView];
UIImageView *backImgg = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,886,15)];
[backImgg setImage: [UIImage imageNamed:#"MUKScale.png"]];//Image in the link above
[scrollView addSubview:backImgg];
[backImgg release];
[scrollView setContentSize:CGSizeMake(886,15)];
return;
}
NSTimer *timer ;
float timeSet =0 ;
-(IBAction) btnPressed
{
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(showTimeInLbl) userInfo:nil repeats:YES];
}
-(void)showTimeInLbl
{
CGRect visibleRect;
visibleRect.origin = scrollView.contentOffset;
visibleRect.size = scrollView.contentSize;
NSLog( #"Visible rect: %#", NSStringFromCGRect(visibleRect) );
float time = visibleRect.origin.x / 8;
timeSet = time;
lblTime.text = [NSString stringWithFormat:#"%f",time];
[UIView animateWithDuration: .1
animations: ^{
[scrollView setContentOffset:CGPointMake(visibleRect.origin.x - 8,0) animated:NO];
}completion: ^(BOOL finished){
}
];
timeSet-=0.1;
lblTime.text = [NSString stringWithFormat:#"%f",timeSet];
if(timeSet<=0)
{
[timer invalidate];
lblTime.text = #"0";
[UIView animateWithDuration: .1
animations: ^{
[scrollView setContentOffset:CGPointMake(0,0) animated:NO];
}completion: ^(BOOL finished){
}
];
}
}
You can use a Never Ended scrollView (For example this you have in it like off paging).
Now by this you will achieve the scale and by using page no or coordinates of the scrollview you can find the scale reading to show on above.
On start count down create animation of UIView contentOffset CGPointMake(10, 100).
for example:
[UIView animateWithDuration: 1.5 /* Give Duration which was also on top */
animations: ^{
[scrollView setContentOffset:CGPointMake(0,0) animated:NO];
}completion: ^(BOOL finished){ }];
Related
I have 3 images in my array for this sample code it just animate without any style .I want to animate like fade in fade out style.
NSArray *imarray = [[NSArray alloc] initWithObjects:
[UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/lady1_open.png", path]],
[UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/lady1_open2.png", path]],
[UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/lady1_open3.png", path]],
nil];
bingo_girl.animationImages=imarray;
bingo_girl.animationDuration=5;
bingo_girl.animationRepeatCount=0;
[bingo_girl.layer addAnimation:transition forKey:nil];
[bingo_girl startAnimating];
You may animate images with transition manually for example using this category
#implementation UIImageView (AnimateTransition)
- (void) assignImage:(UIImage *)image withTransition:(NSString *)withTransition withDirection:(NSString *)withDirection{
if(image == nil)
{
[self setImage:nil];
return;
}
if ([UIImagePNGRepresentation(self.image) isEqualToData:UIImagePNGRepresentation(image)]) {
return;
}
CATransition *animation = [CATransition animation];
animation.duration = 0.2;
animation.type = withDirection;
animation.subtype = withDirection;
[[self layer] addAnimation:animation forKey:#"imageFade"];
[self setImage:image];
}
#end
I have this scrollView:
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.scrollView.contentSize = CGSizeMake(320,3000);
_scrollView.frame = CGRectMake(0, 45, 320, 420);
and I want to make it autoscroll very slowly downward to the end so that the user can see the content (as in movie credits), eventually with a button to stop/play, but to follow the user gestures when touching the interface.
How can I do this?
Thanks,
You can use:
[_scrollView setContentOffset:CGPointMake(x,y) animated:YES];
and use the x and y as the touch points on the screen you can capture.
You can also do an animation with CoreAnimation:
[UIScrollView beginAnimations:#"scrollAnimation" context:nil];
[UIScrollView setAnimationDuration:1.0f];
[scroll setContentOffset:CGPointMake(x, y)];
[UIScrollView commitAnimations];
this adapted code did the trick (source http://sugartin.info/2012/01/21/image-sliding-page-by-page-uiscrollview-auto-scrolling-like-image-slider/)
PS : each image is 280 by 200
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scr=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scr.tag = 1;
scr.autoresizingMask=UIViewAutoresizingNone;
[self.view addSubview:scr];
[self setupScrollView:scr];
UIPageControl *pgCtr = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 264, 480, 36)];
[pgCtr setTag:12];
pgCtr.numberOfPages=10;
pgCtr.autoresizingMask=UIViewAutoresizingNone;
[self.view addSubview:pgCtr];
}
- (void)setupScrollView:(UIScrollView*)scrMain {
// we have 10 images here.
// we will add all images into a scrollView & set the appropriate size.
for (int i=1; i<=10; i++) {
// create image
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:#"sti%02i.jpg",i]];
// create imageView
UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(20, ((i-1)*scrMain.frame.size.height+100), 280, 200)];
// set scale to fill
imgV.contentMode=UIViewContentModeScaleToFill;
// set image
[imgV setImage:image];
// apply tag to access in future
imgV.tag=i+1;
// add to scrollView
[scrMain addSubview:imgV];
}
// set the content size to 10 image width
[scrMain setContentSize:CGSizeMake(scrMain.frame.size.width, scrMain.frame.size.height*10)];
// enable timer after each 2 seconds for scrolling.
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(scrollingTimer) userInfo:nil repeats:YES];
}
- (void)scrollingTimer {
// access the scroll view with the tag
UIScrollView *scrMain = (UIScrollView*) [self.view viewWithTag:1];
// same way, access pagecontroll access
UIPageControl *pgCtr = (UIPageControl*) [self.view viewWithTag:12];
// get the current offset ( which page is being displayed )
CGFloat contentOffset = scrMain.contentOffset.y;
// calculate next page to display
int nextPage = (int)(contentOffset/scrMain.frame.size.height) + 1 ;
// if page is not 10, display it
if( nextPage!=10 ) {
[scrMain scrollRectToVisible:CGRectMake(0, nextPage*scrMain.frame.size.height, scrMain.frame.size.width, scrMain.frame.size.height) animated:YES];
pgCtr.currentPage=nextPage;
// else start sliding form 1 :)
} else {
[scrMain scrollRectToVisible:CGRectMake(0, 0, scrMain.frame.size.width, scrMain.frame.size.height) animated:YES];
pgCtr.currentPage=0;
}
}
You can set x if you want to scroll horizontally, otherwise set y to scroll vertical.
[_scrollView setContentOffset:CGPointMake(x, y) animated:YES];
and modify the co-ordinates accordingly.
I am trying to make a slideshow in an imageview that uses also fade-in fade-out effects.
so far ive done this:
- (void)viewDidLoad
{
[super viewDidLoad];
animationView = [[UIImageView alloc] initWithFrame:self.view.frame];
animationView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"photo1.jpg"],
[UIImage imageNamed:#"photo2.jpg"],
[UIImage imageNamed:#"photo3.jpg"], nil];
animationView.animationDuration = 5;
animationView.animationRepeatCount = 0;
[animationView startAnimating];
[self.view addSubview:animationView];
}
images do appear one after the other, in a 5 sec delay, what i want now is to make them fade-in and fade-out each time an image appears, any suggestions on that?
Thanks in advance for your help
I was trying to do something similar. What I did was setup a timer that called a UIView transitionWithView on a UIImageView that was incrementing through the array of my slideshow photos.
- (void)viewDidLoad{
[super viewDidLoad];
self.welcomePhotos = [NSArray arrayWithObjects:#"welcome_1.png",#"welcome_2.png", #"welcome_3.png", nil];
self.imageView1.image = [UIImage imageNamed:[self.welcomePhotos objectAtIndex:0]];
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:#selector(transitionPhotos) userInfo:nil repeats:YES];
}
-(void)transitionPhotos{
if (photoCount < [self.welcomePhotos count] - 1){
photoCount ++;
}else{
photoCount = 0;
}
[UIView transitionWithView:self.imageView1
duration:2.0
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{ self.imageView1.image = [UIImage imageNamed:[self.welcomePhotos objectAtIndex:photoCount]]; }
completion:NULL];
}
I am working on an iPhone games like application, where I have to ask one question and corresponding answers on UIButoons. When user presses any button I show right and wrong image based on chosen answer. I create answer view by following code and attach it to main view:
-(void)ShowOutputImageAsAnswerView:(BOOL)correct
{
viewTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:#selector(RemoveSubViewFromMainView) userInfo:nil repeats:YES];
UIView *viewOutput = [[UIView alloc]initWithFrame:CGRectMake(200, 100, 80, 80)];
viewOutput.tag = 400;
viewOutput.backgroundColor = [UIColor clearColor];
UIImageView *imgAns = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
if (correct)
{
imgAns.image = [UIImage imageNamed:#"correct_icon.png"];
}
else
{
imgAns.image = [UIImage imageNamed:#"wrong_icon.png"];
}
[viewOutput addSubview:imgAns];
[self.view addSubview:viewOutput];
[self.view bringSubviewToFront:viewOutput];
[imgAns release];
[viewOutput release];
}
I have to show this answer view in the animated form. And this animation will start from its 0 pixel to 80 pixel. Means expanding and shrinking view.
How can it be implemented?
Can it directly be used with imgAns?
You create an animation by doing something like this:
myView.frame=CGRectMake(myView.frame.origin.x,myView.frame.origin.y,0.,0.);
[UIView animateWithDuration:1
animations:^{
//put your animation here
myView.frame=CGRectMake(myView.frame.origin.x,myView.frame.origin.y,80.,80-);
}];
I haven't tried this code, but it should give you a good perspective of how to do it.
I need to assign a view to an NSMenuItem and do some custom drawing. Basically, I'm adding a little delete button next to the currently selected menu item, among other things. But I want my custom menu item to look and behave like a regular menu item in all other ways. According to the doc:
A menu item with a view does not draw
its title, state, font, or other
standard drawing attributes, and
assigns drawing responsibility
entirely to the view.
Ok, so I had to duplicate the look of the state column and the selection gradient, which wasn't that hard. The part I'm having trouble with is the way the menu item "flashes" or "blinks" after it is selected. I'm using an NSTimer to try to mimic this little animation, but it just feels off. How many times does it blink? What time interval should I use? I've experimented a lot and it just feels out of whack.
Has anyone done this before or have other suggestions on how to add a button to a menu item? Maybe there should be a stack exchange site just for custom cocoa drawing...
I know this is over a year old, but this was the first hit on my Google search and was unanswered, so I'm posting my answer for sake of those still looking for a solution.
For my app, I used Core Animation with a custom NSView for the NSMenuItem view. I created a new layer-backed view, set the background color, and added it to my custom view. I then animated the layer (the flashing part). Then in the -(void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag callback, I removed the overlay and closed the menu. This doesn't perfectly match the default NSMenu's flash, but I wanted a 37Signals/Stack Overflow Yellow Fade Technique, so it works for me. Here it is in code:
-(void) mouseUp:(NSEvent *)theEvent {
CALayer *layer = [CALayer layer];
[layer setDelegate:self];
[layer setBackgroundColor:CGColorCreateGenericRGB(0.0, 0.0, 1.0, 1.0)];
selectionOverlayView = [[NSView alloc] init];
[selectionOverlayView setWantsLayer:YES];
[selectionOverlayView setFrame:self.frame];
[selectionOverlayView setLayer:layer];
[[selectionOverlayView layer] setNeedsDisplay];
[selectionOverlayView setAlphaValue:0.0];
[self addSubview:selectionOverlayView];
CABasicAnimation *alphaAnimation1 = [CABasicAnimation animationWithKeyPath: #"alphaValue"];
alphaAnimation1.beginTime = 0.0;
alphaAnimation1.fromValue = [NSNumber numberWithFloat: 0.0];
alphaAnimation1.toValue = [NSNumber numberWithFloat: 1.0];
alphaAnimation1.duration = 0.07;
CABasicAnimation *alphaAnimation2 = [CABasicAnimation animationWithKeyPath: #"alphaValue"];
alphaAnimation2.beginTime = 0.07;
alphaAnimation2.fromValue = [NSNumber numberWithFloat: 1.0];
alphaAnimation2.toValue = [NSNumber numberWithFloat: 0.0];
alphaAnimation2.duration = 0.07;
CAAnimationGroup *selectionAnimation = [CAAnimationGroup animation];
selectionAnimation.delegate = self;
selectionAnimation.animations = [NSArray arrayWithObjects:alphaAnimation1, alphaAnimation2, nil];
selectionAnimation.duration = 0.14;
[selectionOverlayView setAnimations:[NSDictionary dictionaryWithObject:selectionAnimation forKey:#"frameOrigin"]];
[[selectionOverlayView animator] setFrame:[selectionOverlayView frame]];
}
-(void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
[selectionOverlayView removeFromSuperview];
NSMenuItem *enclosingMenuItem = [self enclosingMenuItem];
NSMenu *enclosingMenu = [enclosingMenuItem menu];
[enclosingMenu cancelTracking];
[enclosingMenu performActionForItemAtIndex:[enclosingMenu indexOfItem:enclosingMenuItem]];
}
It is actually possible to have your custom view flash like a regular NSMenuItem without implementing the animation manually.
Note: this uses a private API and also fixes a handful of other strange NSMenuItem quirks related to custom views.
NSMenuItem.h
#import <AppKit/AppKit.h>
#interface NSMenuItem ()
- (BOOL)_viewHandlesEvents;
#end
Bridging Header
#import "NSMenuItem.h"
MenuItem.swift
class MenuItem: NSMenuItem {
override func _viewHandlesEvents() -> Bool {
return false
}
}
This API really ought to be public, and if you're not developing for the App Store, it might be worth having a look at.
Here is my code that flashes a custom menu item.
int16_t fireTimes;
BOOL isSelected;
- (void)mouseEntered:(NSEvent*)event
{
isSelected = YES;
}
- (void)mouseUp:(NSEvent*)event {
fireTimes = 0;
isSelected = !isSelected;
[self setNeedsDisplay:YES];
NSTimer *timer = [NSTimer timerWithTimeInterval:0.05 target:self selector:#selector(animateDismiss:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode];
}
-(void)animateDismiss:(NSTimer *)aTimer
{
if (fireTimes <= 2) {
isSelected = !isSelected;
[self setNeedsDisplay:YES];
} else {
[aTimer invalidate];
[self sendAction];
}
fireTimes++;
}
- (void)drawRect:(NSRect)dirtyRect {
if (isSelected) {
NSRect frame = NSInsetRect([self frame], -4.0f, -4.0f);
[[NSColor selectedMenuItemColor] set];
NSRectFill(frame);
[itemNameFld setTextColor:[NSColor whiteColor]];
} else {
[itemNameFld setTextColor:[NSColor blackColor]];
}
}
- (void)sendAction
{
NSMenuItem *actualMenuItem = [self enclosingMenuItem];
[NSApp sendAction:[actualMenuItem action] to:[actualMenuItem target] from:actualMenuItem];
NSMenu *menu = [actualMenuItem menu];
[menu cancelTracking];
// [self setNeedsDisplay:YES]; // I'm not sure of this
}