Blog Park third-party client-I blog Park officially released app Store1. Objective
From August 15 to now self-learning iOS has been almost 7 months, although the middle is intermittent, but unexpectedly persisted. Years later to find an internship, so the initiation of an idea-write an app to practice practiced hand. This time I did not get backstage, directly using the blog Park Open API (hehe). I've done an app before, called the Magic Realm-magic, I made it back and forth, but the backend uses the Bmob back-end Cloud (a Baas service), but as the first app, the code feels confusing and basically a third-party control. This time I blog Park is completely independent of my development (including UI design), the overall use of the MVC pattern, and try not to use others third-party control (although it is still used. Specific usage will be mentioned later).
Let's start by releasing a few GIF preview images of the app:
AppStore Address:
You can search for I blog Park in AppStore . or scan the following QR code:
2. Information and tools used
- Blog Park official open Web API URL:
- Http://wcf.open.cnblogs.com/news/help (News)
- Http://wcf.open.cnblogs.com/blog/help (blog)
- Third-party controls to use
- Afnetworking
- Sdwebimage
- Hmsegmentedcontrol (segmented Control)
- Residemenu (Slide controller view)
- Mjrefresh
- Masonry (AutoLayout)
- Uitableview+fdtemplatelayoutcell (dynamically calculates the height of the UITableViewCell)
- Xmldictionary (parse XML file, because the blog Park Web API comes back with XML data)
- UI Resources and tools
- http://www.easyicon.net/(icon material)
- Sketch
- Photoshop
3. Issues to solve
Issue one: Implement the Ripplebutton on the boot page (not the Start page) (the button with the rippling animation, the pink button on the first GIF image)
Solution Ideas:
1. Use Uibesierpath to build a circular path
Uibezierpath *path = [Uibezierpath bezierpathwithroundedrect:pathframe CornerRadius:self.layer.cornerRadius];
2. Assign the above path to the Path property of the CircleShape (Cashapelayer object), and add the CircleShape to the Ripplebutton (UIView type)
Cashapelayer *circleshape == path. Cgpath;
[Self.layer Addsublayer:circleshape];
3. At this point, you can use the core animation to manipulate the layer of the Ripplebutton, details I will not be detailed, nothing more than the animation to control the scale and alpha of the circle
Cabasicanimation *scaleanimation = [cabasicanimation animationwithkeypath:@"Transform.scale"];scaleanimation.fromvalue=[Nsvalue valuewithcatransform3d:catransform3didentity];scaleanimation.tovalue= [Nsvalue Valuewithcatransform3d:catransform3dmakescale (2.5,2.5,1)]; Cabasicanimation*alphaanimation = [Cabasicanimation animationwithkeypath:@"Opacity"];alphaanimation.fromvalue= @1; Alphaanimation.tovalue= @0; Caanimationgroup*animation =[Caanimationgroup animation];animation.animations=@[scaleanimation, Alphaanimation];animation.duration=1.0f; Animation.timingfunction=[Camediatimingfunction functionwithname:kcamediatimingfunctioneaseout]; [CircleShape addanimation:animation Forkey:nil];
4. However, if you add only one circleshape, there will be no effect of multiple waves dispersing. I then encapsulated the above 123-step code into a createrippleeffect function and added it to the timer
- (void) setuprippletimer{__weak __typeof__ (self) weakself=Self ; Nstimeinterval Repeatinterval=Self.repeatinterval; dispatch_queue_t Queue= Dispatch_get_global_queue (Dispatch_queue_priority_default,0); Self.timer= Dispatch_source_create (Dispatch_source_type_timer,0,0, queue); Dispatch_source_set_timer (Self.timer, Dispatch_time_now, Repeatinterval* Nsec_per_sec,0); __block Nsinteger Count=0; Dispatch_source_set_event_handler (Self.timer,^{Dispatch_async (Dispatch_get_main_queue (),^{Count++; //number of water ripple repeats, default-1, indicates permanent if(Self.repeatcount! =-1&& Count >weakself.repeatcount) {[Weakself stoprippleeffect]; return; } [weakself createrippleeffect]; }); });}
question two: 48 hours reading and 10th recommendations using the Uicollectionview, custom uicollectionviewlayout to achieve the effect of roulette rotation (part of the Code reference Awcollectionviewdiallayout )
Solution Ideas:
1. First you need to know the specific process of customizing uicollectionviewlayout
To implement the specific process of customizing the Uicollectionviewlayout please refer to this article, very detailed!
2. Throughout the custom Uicollectionviewlayout implementation process, the core number layoutattributesforelementsinrect this function.
2.1 First calculates the number of cells in the current rect based on the Y value of the rect:
//There are several cells in this area of rect that return the properties of each cell-(nsarray<uicollectionviewlayoutattributes *> *) Layoutattributesforelementsinrect: (cgrect) rect{Nsmutablearray*layoutattributes =[Nsmutablearray array]; CGFloat Miny=cgrectgetminy (rect); CGFloat Maxy=Cgrectgetmaxy (rect); //get to the firstindex and lastindex of cells in this area of rect, these two are useless, mainly to get ActiveindexNsinteger firstindex = Floorf (Miny/self.itemheight); Nsinteger LastIndex= Floorf (Maxy/self.itemheight); Nsinteger Activeindex= (FirstIndex + lastIndex)/2;//the middle cell is set to active .//Maxvisiableonscreeen indicates the maximum number of cells in the current screen//angularspacing indicates how many times a cell is counted, because this is a roulette wheel, and each cell is actually a fanNsinteger Maxvisiableonscreeen = the/self.angularspacing +2; //FirstItem and LastItem indicate which cells are in the current rectNsinteger FirstItem = Fmax (0, Activeindex-(Nsinteger) maxvisiableonscreeen/2); Nsinteger LastItem= Fmin (Self.cellcount, Activeindex + (Nsinteger) maxvisiableonscreeen/2); if(LastItem = =self.cellcount) {FirstItem= Fmax (0, Self.cellcount-(Nsinteger) maxvisiableonscreeen); } //computes the uicollectionviewlayoutattributes of each cell in a rect for(Nsinteger i = FirstItem; i < LastItem; i++) {Nsindexpath*indexpath = [Nsindexpath indexpathforitem:i insection:0]; Uicollectionviewlayoutattributes*attributes=[self layoutattributesforitematindexpath:indexpath]; [Layoutattributes addobject:attributes]; } returnlayoutattributes;}
2.2 Calculating the uicollectionviewlayoutattributes of each cell
-(Uicollectionviewlayoutattributes *) Layoutattributesforitematindexpath: (Nsindexpath *) indexpath{//default offset is 0CGFloat NewIndex = (Indexpath.item +self.offset); Uicollectionviewlayoutattributes*attributes =[Uicollectionviewlayoutattributes Layoutattributesforcellwithindexpath:indexpath]; Attributes.size=self.cellsize; CGFloat Scalefactor, DeltaX; Cgaffinetransform Translationt; Cgaffinetransform Rotationt; Switch(self.wheetalignmenttype) { CaseWheetalignmenttypeleft:scalefactor= Fmax (0.6,1-Fabs (NewIndex *0.25)); DeltaX= Self.cellSize.width/2; Attributes.center= Cgpointmake (-self.radius + self.xoffset, self.collectionview.height/2+self.collectionview.contentoffset.y); Rotationt= Cgaffinetransformmakerotation (self.angularspacing * newindex * M_PI/ the); Translationt= Cgaffinetransformmaketranslation (Self.radius + deltax * scalefactor,0); Break; CaseWheetalignmenttyperight:scalefactor= Fmax (0.6,1-Fabs (NewIndex *0.25)); DeltaX= Self.cellSize.width/2; Attributes.center= Cgpointmake (Self.radius-self.xoffset + icdevicewidth, self.collectionview.height/2+self.collectionview.contentoffset.y); Rotationt= Cgaffinetransformmakerotation (-self.angularspacing * newindex * M_PI/ the); Translationt= Cgaffinetransformmaketranslation (-Self.radius-deltax * scalefactor,0); Break; CaseWheetalignmenttypecenter://Pending Implementation Break; default: Break; } cgaffinetransform Scalet=Cgaffinetransformmakescale (Scalefactor, scalefactor); Attributes.alpha= Scalefactor;//Alpha and Scalefactor consistent//The scale is scaled down, translation to the corresponding position (because it is a fan, the X value of each cell is related to the corresponding position), and the final rotation (forming an arc)Attributes.transform =Cgaffinetransformconcat (Scalet, Cgaffinetransformconcat (Translationt, Rotationt)); Attributes.zindex=Indexpath.item; returnattributes;}
Problem three: Realizing the tabbaritem of driving painting
Solution Ideas:
In detail, I submitted the code to GITHUB-ANIMATED-TAB-BAR-OBJECTIVE-C (Pjxanimatedtabbarcontroller is a objective-c version of Ramanimatedtabbarcontroller (https://github.com/Ramotion/animated-tab-bar)).
This is primarily a custom uitabbaritem, as well as a custom Uitabbaritem AutoLayout build. Code encapsulation is very good, especially the animation implementation part, the structure is very clear, in line with the OOP idea.
Question four: The blog park uses the XML form of the open Web API. Difficult to parse.
Solution Ideas:
Here I still use the MVC approach, using afnetworking to get the XML data, and then use Xmldictionary to parse the XML data (essentially nsxmlparserdelegate) and convert it into model (it needs to be implemented).
For Nsxmlparserdelegate, you can refer to this article-the parsing XML file for iOS development .
Question five: The design part, not very good, each page layout needs to think for a long time, as far as possible to do concise, has the science and technology wind.
Solution Ideas:
Basically is to look at other people's app design, imitation, or think about it. It is also the first time to use sketch, words are very useful.
4. Problems and Todo
- Share to Weibo and so on, ready to use Friends League.
- Related to the UIWebView interface layout, very ugly. Not very understand CSS, JS, HTML5. In order to a picture for a half-day, in fact, as long as the
- Hiding Tabbar is cumbersome after you use custom Tabbaritem.
- Offline reading
- ......
5. PostScript
It's really not the same, a lot of detail, though it's not hard, but it's very challenging to write your own code. The code is very lame, and the spec point is modified later, ready to be put on GitHub.
Blog Park third-party client-I blog Park officially released app Store