How to create a piano UI in Iphone?

I am new to creating such a piano based application. I am developing an application in which I have to use the piano. How to create a piano UI in Iphone? How to create it using Interface Builder? or is there another way to create a piano?

I urgently need to create such an interface if any authority has any solution or some useful code or some link that would be appreciated.

Thanks Niraj

+3
source share
5 answers

Version 1 Easier to code, not so elegant.

xcode , MyProjectViewController.xib, , .

MyProjectViewController.h .m, :

- (IBAction) playMiddleC: (id) sender;
- (IBAction) playMiddleD: (id) sender;
- (IBAction) playMiddleE: (id) sender;

File Owner ( MyProjectViewController). , , - .

, . , , midC.caf (, , PCM, ). , ( xcode) "" "" > " ", .

AudioToolbox . , Frameworks "" > " ", AudioToolbox .

, MyProjectViewController.m, :

#import <AudioToolbox/AudioServices.h>

// (Later...)

- (IBAction) playMiddleC: (id) sender {
  NSString* path = [[NSBundle mainBundle]
                    pathForResource:@"midC" ofType:@"caf"];
  NSURL* url = [NSURL URLWithString:path];
  SystemSoundID midC;
  AudioServicesCreateSystemSoundID((CFURLRef)url, &midC);
  AudioServicesPlaySystemSound(midC);
}

Hit Command-Enter !

2 .

, ( ). UIButton (, C/F, B/E A/D/G, - ).

, , .

, , . AudioQueue, , , , "" . , .

,, , , . iPhone - , , . , , , , UITableView , , ( , iPhone SDK ).

!

+9

...

.

- .

CGFloat buttonWhitePosX = 2.0; //white button start position
for(int i=0;i<8;i++){ //8 keys in one octave
    CGFloat buttonWhitePosY = 105;
    CGFloat buttonWhiteWidth = 57;
    CGFloat buttonWhiteHeight = 190;

    UIButton *buttonWhite = [[UIButton alloc] initWithFrame:CGRectMake(buttonWhitePosX, buttonWhitePosY, buttonWhiteWidth, buttonWhiteHeight)];
    buttonWhitePosX = buttonWhitePosX + WHITE_BUTTON_SPACE + buttonWhiteWidth;
    [buttonWhite setBackgroundImage:whiteImage forState:UIControlStateNormal];
    [buttonWhite addTarget:self action:@selector(pressButtonWhiteTouchDown:) forControlEvents:UIControlEventTouchDown];

    buttonWhite.tag = i;
    [buttonWhite setBackgroundImage:whiteImageHighlighed forState:UIControlEventTouchDragInside];
    [self.view addSubview:buttonWhite];
    [buttonWhite release];

}

.

AVPlayer. ( )

, , .

1) UIControl UIButton. DragEnter, , . , ,

2) Began, touchsEnded, touchsMoved ( ).

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:touch.view];
    currentView = [self.view hitTest:touchLocation withEvent:nil]; //get top view
    if(currentView != self.view){ //check current view is main view, do nothing
        if(currentView == prevView){ //check current view is prev view, keep highlight image
            currentView.backgroundColor = [UIColor colorWithPatternImage:whiteImageHighlighed];
        }else{ //view changed, change image and play sound
            prevView.backgroundColor = [UIColor colorWithPatternImage:whiteImage];
            currentView.backgroundColor = [UIColor colorWithPatternImage:whiteImageHighlighed];
            [self pressButtonWhiteDown1:currentView.tag];
            prevView = currentView;
        }
    }
}

, X ( ):

alt text http://img215.yfrog.com/img215/1720/pianohelp.png

- -, / . , .

?

.

+2

- - .

Photoshop , , , .

. , , .

, , . , Quartz 2D , , CAAnimation.

+1

- . WAV. !

0

Source: https://habr.com/ru/post/1715494/


All Articles